调试蓝调

时间:2016-02-16 19:05:07

标签: java debugging

帮助,我收到了代码中的以下错误。我有点新鲜,我不明白为什么我会收到这些错误。

java 49: error : ')' expected

java 49: error : ';' expected

java 58: error: reached end of file while parsing
import java.io.*;
import java.util.*;
import java.lang.*;

public class ProductDAO {
    private String filename;
    private ArrayList<Product> products;

    public ProductDAO(String filename) {    
        this.filename = filename;
        load();
    }

    private void load() {
        // TODO: update this method
        try {

            AppException a = new AppException("Cannot Load", FileNotFoundException);
            AppException b = new AppException("Invalid Number of Products");

            File f = new File(filename);
            Scanner sc = new Scanner(f);
            Scanner scDl = sc.useDelimiter("\r\n");
            String listDes = scDl.nextLine();
            int numOfProducts = Integer.parseInt(listDes.substring(listDes.length()-1));

            String productList = scDl.nextLine();

            while (scDl.hasNextLine()) {
                productList = scDl.nextLine();
                ArrayList<String> prodDetail = new ArrayList<>(Arrays.asList(productList.split(":")));
                String name = prodDetail.get(0);
                double price = Double.parseDouble(prodDetail.get(1));
                int quantity = Integer.parseInt(prodDetail.get(2));
                Product prod = null;
                if (prodDetail.get(3).equals("yes")) {
                    String expiryDate = prodDetail.get(4);
                    prod = new Food(name,price,quantity,expiryDate);
                } else {
                    prod = new Product(name,price,quantity);
                }
                products.add(prod);
            }

            if (products.size()!=numOfProducts) {
                throw b;
            }

        } catch (Exception a.getCause()) {
            a.getMessage();
        }

    }

    private void save() {
        // TODO: update this method
    }
}

1 个答案:

答案 0 :(得分:0)

错误的异常捕获块:

} catch (Exception a.getCause()) {

应该是:

} catch (Exception a) {

即。异常类后面只能跟着你以后引用的变量名。