Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/base35/errorbase.net/qa-include/qa-db.php on line 50Java.lang.IndexOutOfBoundsException - Errorbase

Java.lang.IndexOutOfBoundsException

+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();
arr.add("someStringHere");
for (int i = 0 ; i < 5 ; i++) {
arr.get(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.)

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(SomeClass.java:16)
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.