I get an error on:
line = node_reader.readLine();
When the text file is empty I get a NullPointerException error. If there is data on the text I do not get the error. What am I doing wrong?
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;
}
}
}
This is the text file:
138 102 100 36 0
95 293 100 36 1
The problem lies in
Inside this method, the file is probably not opened correctly. Go to this method and validate that the method correctly creates a BufferedReader.