Follow Us
  • Register
Errorbase is a collaborative writing project, that aims to build the largest trouble-shooting guide about all kinds of error messages.


+2 votes

This exception is thrown in java when the index is higher than the size of a vector, arraylist, array etc... Ex:
ArrayList arr = new ArrayList();
for (int i = 0 ; i < 5 ; i++) {

The above example will throw IndexOutOfBoundsException, because the arraylist contains only 1 string and the index is going further than 0.  (Also in Java the indices start with 0.)

requested by (170k points)
edited by

1 Solution

0 votes

The thrown exception shows the line number in which the problem has occured. The exception thrown for the above example is like this:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at SomePackage.SomeClass.main(

For this example the problem has occured in line 16. Additionally Index: 1 shows the index that we tried to reach and Size: 1 tells us the actual size of the variable.

solved by (170k points)
edited by
java.lang.IndexOutOfBoundsException: Index: 3, Size: 3