From the ArrayIndexOutOfBoundsException documentation:
Thrown to indicate that an array has been accessed with an illegal index. The size of the array.
Thrown to indicate that the array was accessed at an incorrect index. The index is either negative or not less than the size of the array.
Those. an array of length l can be accessed by indices from 0 to l-1 .
The error occurs either when addressing the negative element of the array:
int[] arr = new int[10]; arr[-1] = 1; //ΠΎΡΠΈΠ±ΠΊΠ°, Π½Π΅Ρ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ° -1
either to the element beyond the top of the array
int[] arr = new int[10]; arr[10] = 1; //ΠΎΡΠΈΠ±ΠΊΠ°, Π½Π΅Ρ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ° 10
In this case, an incorrect index is indicated in the error message:
java.lang.ArrayIndexOutOfBoundsException: 0
In this case, the length of the array is 0:
int x = 0, y = 0; int Arr1[] = new int[x]; // x = 0 ΠΏΡΡΡΠΎΠΉ ΠΌΠ°ΡΡΠΈΠ²
Accordingly, it is impossible to refer to its elements, they are not. Try setting the length of the array.