Maybe adding the variables amountOfRows and amountOfCols like I did here, helps you see where you went wrong:
I think it's good for you to play around with Java and ArrayList's like that. A few suggestions:
- catch a good book or website (possibly a page on the Java FAQ here too about it) about Java and read about collections and specifically about iterators
- consider looking into an existing API like CSV4J or even Apache POI (just 2 examples) to do all the work for you
- if the application grows it might be good to consider putting the data in a database of some sorts instead of a csv
Michael Comerford wrote:... an IndexOutOfBoundsException ... I've had a look through the documentation for this exception and don't see how to resolve it, any clues?
An exception like this
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
should be read in the following way:
You're trying to access an element (of an ArrayList for example) at index 4 while the size of the ArrayList is only 4. Remember that this is 0-based so the 4 elements are at indexes 0, 1, 2 and 3. Hence the 'index out of bounds'; you're trying to access something that doesn't exist.
posted 9 years ago
Wim thanks that was a really useful explanation, I fixed the problem and the code works now.
Get me the mayor's office! I need to tell him about this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!