Follow Us
Contribute
  • Register

Java.lang.ArrayIndexOutOfBoundsException

0 votes

This exception is thrown in java when the index is higher than the size of the array. Ex:
int[] arr = {1, 2, 3, 4, 5};
int x = arr[6];

The above example will throw ArrayIndexOutOfBoundsException, because the array contains only 5 integer elements and the index is 6.

requested 7 years ago by errorbase (170,010 points)
edited 7 years ago by onur

1 Solution

+1 vote

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.ArrayIndexOutOfBoundsException: 6
at SomePackage.SomeClass.main(SomeClass.java:9)

For this example the problem has occured in line 9. By this way you can reach the variable which created the problem. After finding the variable, debug the code for that variable.

solved 7 years ago by errorbase (170,010 points)
edited 7 years ago by onur
Nokia browser

Related errors

+1 vote
1 solution
0 votes
1 solution
+2 votes
1 solution