Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/base35/ on line 50
Java.lang.IndexOutOfBoundsException - Errorbase
Follow Us
  • Register


+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 6 years ago by errorbase (170,010 points)
edited 5 years ago by onur

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 6 years ago by errorbase (170,010 points)
edited 5 years ago by onur
java.lang.IndexOutOfBoundsException: Index: 3, Size: 3

Related errors

+1 vote
1 solution
0 votes
1 solution
0 votes
1 solution
0 votes
0 solutions