-1

When i run the program, i keep getting the following error:

enter image description here

I read data from a file and add it to a LinkedList but I keep getting this error when I run the program. It also skips every other line from the file which is annoying. Every other line gets added as an "Worker" object to the list fine but I don't know how to get over this problem, any ideas? Here is the code:

BufferedReader sbr = new BufferedReader(new FileReader("src/stafflist.csv"));
            LinkedList<Worker> workerList = new LinkedList<Worker>();
            while (sbr.readLine()!=null){
              String[] lines = sbr.readLine().split(",");
                Worker worker = new `enter code here`Worker(lines[0],Integer.parseInt(lines[1]),null);
                workerList.add(worker);
                System.out.println(worker.toString());
            }
DimaSan
  • 12,264
  • 11
  • 65
  • 75
  • It means the String you are trying to split is `null`. – Andrei Olar Nov 22 '16 at 09:25
  • Here is the contents of the file, it shouldn't be null: http://imgur.com/a/1m0FY Surely the while loop should stop once it reaches null – George Herzl Nov 22 '16 at 09:27
  • 1
    The contents of the file does not have to be the String you are trying to split. Nobody knows what you have done there since you did not post any code. Please post code instead of images. – Andrei Olar Nov 22 '16 at 09:31

1 Answers1

3

In a while-loop you read data and just throw it away, then inside the loop trying to get some more data and this data is null. Put your data from while() in a variable! And post code rather screens.

Michel_T.
  • 2,741
  • 5
  • 21
  • 31