0

I'm making a minesweeper game in java, and I have declared a 2d array of Tile objects as the game board. 2d array board is declared as an instance variable, then filled with Tile objects once the user passes a size (4x4 to 10x10, inclusive). I then attempt to call a method on a specific object from another method in class GameBoard using the format board[a][b].setMarked(true). I receive the error "cannot find symbol - method setMarked(boolean)". I'm confused as to how GameBoard cannot see the method in Tile, since it was declared as public and I can call it from a non-array object. I'm assuming it has to do with the instance variables and constructors?

GameBoard class relevant code:

public class GameBoard {
    private Object[][] board;

    public GameBoard(int a) {
        board = new Object[a][a];
        for (int i=0; i<a; i++) {
            for (int j=0; j<a; j++) {
                board[i][j] = new Tile(false);
            }
        }
    }

    public void mark(int a,int b) {
        board[a][b].setMarked(true);
    }
}

Tile class relevant code:

public void setMarked(boolean m) {
    marked = m;
}

where marked is a boolean instance variable declared in Tile.

1
  • I thought so too, and tried it with no luck Commented Feb 15, 2017 at 18:17

1 Answer 1

1

You have array of objects, and Object have no method setMarked(boolean m), think about changing it to array of Tiles

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I kinda thought it would be something that easy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.