0

The Array containing the object's details is out of bounds. It would say "Index 1 out of bounds for length 1". However When I printing the strings and arrays and it seems to be captured. Even the array lengths are 3 not 1, but still the error persists

Also, initially, I was able to make this work by putting columns.split("\s+") but after a few runs it went back to this Index 1 out of bounds for length 1.... See Image to see how the problem looks.

What did I miss?

Added Println statement to see what it reads per line.

Anish B.
  • 9,111
  • 3
  • 21
  • 41
Jon
  • 23
  • 1
  • 5
  • 2
    Looks like you probably read a blank line from the file. You should put all your `println` statements *before* you try and access the values in `columns`, that way you will see the values which are causing your error. – Nick Aug 01 '20 at 02:49
  • Yeah @Nick has a point. Either the line is blank OR it is missing the `FIELD_SEP` separator in which case `line.split` will return an array of only one item; the entire `line` – efemoney Aug 01 '20 at 02:56
  • https://meta.stackoverflow.com/a/285557/7733418 – Yunnosch Aug 01 '20 at 04:38
  • Please provide code as **text** inside your question. – Mark Rotteveel Aug 01 '20 at 07:08

3 Answers3

0

In the while loop, you should print the line before you split it, so that you know what the line contains.

As Nick already suggested, maybe the line is blank or it does not have the FIELD_SEP as per what you expect.

fauzimh
  • 594
  • 4
  • 16
0

I think you need to check your conversionsFile and somwhere in that file, there might be a line where it will be having only one value/column (i.e not a proper data) instead of having all the three values.

0

This line is giving error :

String toUnit = columns[1];

I think the value at this index doesn't exist, i.e, the array size is 1.

Possible Root cause : The split is not properly happening or if you are splitting the value, only one value is extracted.

Check the file whether you have set the value or not so that it should be there in the array. Otherwise, you will get that error.

Anish B.
  • 9,111
  • 3
  • 21
  • 41