文字列のリストをファイルに保存し、それらを配列リストに読み込むプログラムを作成しようとしています。これが私の現在のコードです。
ObjectInputStream input = null;
try {
input = new ObjectInputStream(new FileInputStream("friends.txt"));
} catch (FileNotFoundException e) {
File f = new File("friends.txt");
try {
f.createNewFile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String obj;
try {
while ((obj = (String)input.readObject()) != null) {
friendly.add(obj);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
これはヌルポインタ例外を返します。ここで何がうまくいかないのかよくわかりません。