使用objectinputstream的空指针异常

时间:2015-04-01 14:24:17

标签: java arrays input nullpointerexception

我正在尝试阅读这个名单和电话号码列表。但该程序一直在抛出nullpointerexception。为什么要这样做?

int i=0;
        Datab[] b = null;
         //b = null;

        // The name of the file to open.
        String fileName = "datt.dat";

        try {
            // Use this for reading the data.
            byte[] buffer = new byte[1000];
            FileInputStream FileIS = new FileInputStream("datt.dat");
            ObjectInputStream input = new ObjectInputStream(FileIS);

            for(i=0; i<b.length; i++)
             b[i]=(Datab)input.readObject();

            input.close();

1 个答案:

答案 0 :(得分:1)

b为null,因此b.length抛出异常