为什么代码无法消除!无法读取可筛选文件?

时间:2017-04-17 17:10:40

标签: java swing nullpointerexception

为什么代码无法消除!无法读取可格化的文件! 它在文件中正确写入但无法读取

enter image description here

public ArrayList<customer> read_file(){
ArrayList <customer>file = new ArrayList<customer>();
try {
    File f= new File("file.bin");
    ObjectInputStream is= new ObjectInputStream (new FileInputStream("file.bin"));
    int x=(int) f.length();


    while(is.available()!=0){
    file.add((customer)is.readObject()) ;

    }
} catch (FileNotFoundException ex) {
    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException | ClassNotFoundException ex) {
    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}

return file ;}

1 个答案:

答案 0 :(得分:0)

您的错误是空指针异常。您将客户数组初始化为null。我建议改用ArrayList。