This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am reading a text file of student names with test scores. Each line of data is separated by a blank line. I am adding the students into an array list and parsing the fields into columns. My code for this is below and it works perfectly if I remove the blank lines in the text file, but when I keep the blank lines I am getting an ArrayIndexOutOfBoundsException. FIELD_SEP is defined as " " since the records are delimited by a space (e.g. lastname firstname score)
How do I skip these blank lines, given my code below? What am I doing wrong? THANKS!
Note that I have tried adding and if statement to check for length == 0 but I just get into an endless if/while loop.
Of course it is, didn't notice it before. You are reading line before you enter while loop, so when you do continue; when line is empty it enters while loop with the same empty line again (because you read next at line 19, and that statement is not reached because of continue;).
What should be done is to remove that statement at line 19 and read file line by line at the beginning of the while: