int myArray[]={1,2,3,4,5,6,7,8};
Here, given array length is 8 as the count starts from 1 but coming for the index myArray[0] = 1;
and so on.... here index count starts from 0.
So in your piece of code
for(int counter = myArray.length - 1; counter >= 0; counter--) {
goes out of the array boundary so it shows you ArrayIndexOutOfBoundsException
.