I'm almost certain you're misreading the line that's triggering the error.
String[] lineArray = new String[4]; // this is not needed, it gets overwritten
...
try {
br = new BufferedReader(new FileReader(listInput));
String line = br.readLine();
while(line != null){
line = br.readLine();
line = line.toUpperCase(); // this will NPE
...
lineArray = null; // you don't need this
}
}
The problem is, you're calling readLine()
a second time inside your while-loop, meaning line
could now be null
. Instead, do this (note the try-with-resources syntax as well):
try(BufferedReader br = new BufferedReader(new FileReader(listInput))) {
String line = null;
while((line=br.readLine()) != null){
String[] lineArray = line.toUpperCase().split("\\s+");
tm1.put(lineArray[0], lineArray[1]);//Place array items into treemaps.
tm2.put(lineArray[0], lineArray[2]);
tm3.put(lineArray[0], lineArray[3]);
System.out.print(tm1 + "\n" + tm2 + "\n" + tm3 + "\n");//Test if data is received
}
}