Basically, I’m implemeting a reversi app for android for my year 13 coursework and this snippet of code is meant to setup the board which is shown here as an array of the class position. However, when run, the app crashes.
Position[][] board = new Position[7][7]; //declaring the board//
for(int n = 0; n < 8; n ++){
...
for(int i = 0; i < 8; i++ ){
final ImageView button = new ImageView(this);
final int countN = n;
final int countI = i;
board[countI][countN].isPositionEmpty = true; //assigning a value//
Any help would be much appreciated!! thanks in advance!
Your for loop goes from 0 to 7 which is actually 8 cells. So you need 8 position objects.
or if you want it to be a 7 by 7 board you need to stop at the 6th index