将string []转换为int []时的java nullPointerException

时间:2014-05-11 02:50:08

标签: java nullpointerexception

下面我有一个学校项目的摘录,我正在尝试调试它,但我正在失去我的头,我正在使用自动生成的文本文档,但在第47行,当我试图打破第3行.txt到库存计数整数我继续得到nullPointerException错误,我已经尝试将它放入if语句但我似乎仍然不想摆脱nullPointerException,如果有人可以帮助我将非常感激。 的问候,

public static void main(String[] args) throws IOException {
    if(fis1.isFile() == true) {
        try{
            InputStream = new BufferedReader(new FileReader(
                "I:/WORKSPACE/Vending Machine/src/Vendor/SETTINGS.txt"));
            String l1;
            String l2;
            String l3;
            l1 = InputStream.readLine();
            l2 = InputStream.readLine();
            l3 = InputStream.readLine();

            stocks = l1.split("-");
            String[] stockprcstr =  l2.split("-");

            for(int i = 0; i < stockprcstr.length; i++) {
                if(stockprcstr[i] == null) {
                    stockprc[i] = 0.0;
                } else {
                    stockprc[i] = Double.parseDouble(stockprcstr[i]);
                }
            }

            String[] stockstr = l3.split("-");
            for(int i = 0; i < stockstr.length;i++) {
                if(stockstr[i] == null){
                    stock[i] = 0;
                } else {
                    System.out.println("int stock: " +  String.valueOf(stock[i]));
                    System.out.println("str stock: " + stockstr[i]);

                    stock[i] = Integer.parseInt(stockstr[i]);
                }
            }
        } finally {
            if(InputStream != null){
                InputStream.close();
            }
        }
    } else {
        PrintWriter writer = new PrintWriter("I:/WORKSPACE/Vending Machine/src/Vendor/SETTINGS.txt");
        writer.println("pipsi-note Cola-Tactical Bacon-Crunchin Crisps-");
        writer.println("2.50-3.00-4.00-3.50-");
        writer.println("5-5-5-5-");
        writer.close();
    }
}

}

0 个答案:

没有答案