0

I am trying to get an excel file in a javafx project, but I am getting the error

error: java.lang.ArrayIndexOutOfBoundsException.

in line 3 of the following code (the call to the Record constructor):

while ((line = br.readLine()) != null) {
    String[] fields = line.split(FieldDelimiter,-5);
    Record record = new Record(fields[0], fields[1], fields[2], fields[3], fields[4], fields[5], fields[6], fields[7], fields[8], fields[9], fields[10], fields[11], fields[12], fields[13], fields[14]);
    dataList.add(record);
} 
Sedrick
  • 10,209
  • 3
  • 35
  • 49
Jordy Pouw
  • 11
  • 3
  • Welcome to SO. Your code seems to be missing an opening `{`. Did it get lost during copying the code here? Furthermore, can you provide more detail on where the error occurs (which line does the compiler complain about)? – m00am Dec 07 '17 at 10:44
  • thank you, my code has an opening { the error occurs at line 3 from this code, i have tried a lot of things but it just won't work. it says that my array isn't correct but i have at least enough 'fields[0]'parts (the number between [ ] keeps adding up till 15 as you can see], but i don't need enymore of those i have seen and counted. so i dont know what is going wrong – Jordy Pouw Dec 07 '17 at 10:53
  • Obviously at least one line does not contain 14+ delimiters. Are you sure the file is stored as CSV? Otherwise retrieving the data from the file is a bit more complex. – fabian Dec 07 '17 at 11:25
  • Closed as I was writing an answer :(. For your specific problem: At least one line in your input is not split into at least 15 entries by your code. You can try finding out which one by checking the length of `field` and then print all lines with `field.length() != 15`. That should shed some light on your problem. – m00am Dec 07 '17 at 11:27

0 Answers0