ArrayIndexOutOfBound exception even though I check for array length!

Posted by xtracto on Stack Overflow See other posts from Stack Overflow or by xtracto
Published on 2010-05-30T18:24:28Z Indexed on 2010/05/30 18:32 UTC
Read the original article Hit count: 138

Filed under:

I have the following code in some app:

int lowRange=50;
int[] ageRangeIndividual = {6, 10, 18, 25, 45, 65, 90};
int index=0;
for (; index<ageRangeIndividual.length-1 && ageRangeIndividual[index]<=lowRange;index++);

I am getting an "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7" in the for line! even though I explicitly specify to break the cycle if index < last indexable item in the array!

This does not happen always, but after some time of running said program (lowRange varies each time the function is called)

What am I not seeing?

© Stack Overflow or respective owner

Related posts about java