讀我得到一個錯誤:NullPointerException異常錯誤,當我從一個文本
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
什麼是'int()' –
什麼是'split(line,...)'? – NPE
NullPointerException發生在哪裏? – nhahtdh