Sunday 14 February 2016

Solving java.lang.ArrayindexOutOfBoundsException: 1 in Java

The error ArrayIndexOutOfBoundsException: 1 means index 1 is invalid and it's out of bound i.e. more than the length of the array. Since array has a zero-based index in Java, this means you are trying to access the second element of an array which only contains one element. The ArrayIndexOutfBoundsException comes when your code, mostly for loop tries to access an invalid index of the array. If you have worked in C, C++ then you will notice this difference between array in C and Java. You simply cannot access invalid array index in Java i.e. indexes which are less than zero and more than the length of the array. ArrayIndexOutOfBounds is also a subclass of IndexOutOfBoundsException which is used to throw error related to invalid index e.g. try to access outside of length in String etc.
Read more »

No comments:

Post a Comment