Referring to the Java documentation Class ArrayIndexOutOfBoundsException , this exception is thrown when you try to access an element that is either negative, or greater than the size of the Array.
Consider the case you have 10 items in the array. You can ask the system what is the first to the tenth item within the array. If you try to ask what is the -1 item or the 100th item in the array, Java would response with the above exception. Now keep in mind that Array in Java is 0 indexed. Therefore, you can only pass an index value of 0 to 9 inclusive. Any number not in this range will throws the specific error mentioned above.
To avoid this exception, let's go back to the concept of CS101, and review the concept of loop invariant. This is a condition to make sure that the variable you use to store the index must be meet the particular condition.
Here is a link to loop invariant: wikipedia > Loop invariant