我收到一个错误:
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