Click to See Complete Forum and Search --> : Index OOB Exception Error


conundrumcomplex
July 15th, 2009, 02:41 PM
I'm sure you've all become quite familiar with this "four letter word" in your travels, as have I.

The exact error is as follows:
-----
Exception in thread "main" java.lang.IndexOutOfBoundsException. Index:4 Size: 4.
at java.util.ArrayList.RangeCheck(ArrayList.java:546)
-----
What I don't really get, is before getting this message, I wasn't dealing with arrays(or ArrayLists), but a StringBuilder value I had just inserted. At that point, i get this error.

Is there anyway, to detect if it really IS a fluke arraylist exception error, elsewhere in my code. And if so, is there a simple way of finding this fluke code?

=Thanks

dlorde
July 16th, 2009, 04:00 AM
I don't know what you mean by a 'fluke' error, but errors in programs are usually the result of mistakes or omissions. StringBuilder uses arrays internally, but it's pretty unlikely to be a bug in StringBuilder - it's more likely that it is being used incorrectly - if you look at the API docs, there are methods that will throw this exception if you pass incorrect arguments.

If you have the full stack trace (you seem to have posted just the first two lines), the first line you come to that refers to a class or method in your own code will tell you where to look first. Without seeing the relevant code and the full stack trace, it's not possible to be more specific.

It is easier to measure something than to understand what you have measured...
Anon.