次のエラーが表示されます。
line = node_reader.readLine();
テキストファイルが空の場合、NullPointerException
エラーが発生します。テキストにデータがある場合、エラーは発生しません。私は何を間違っていますか?
void file_open () {
String line = "test";
BufferedReader node_reader;
node_reader = createReader("nodedata.txt");
while (line !=null ) {
try {
line = node_reader.readLine();
if ( line != null ) {
String[] pieces = split(line, TAB);
int a = int(pieces[0]);
int b = int(pieces[1]);
int c = int(pieces[2]);
int d = int(pieces[3]);
int e = int(pieces[4]);
listofNodes.add(new Node(a, b, e)); //
}
} catch (IOException e) {
e.printStackTrace();
line = null;
}
}
}
これはテキストファイルです:
138 102 100 36 0
95 293 100 36 1