0

For a school assignment, I was making a game of Othello. I was modifying a TicTacToe game I made for the same course a few months earlier. Partway through, I realized that I had not changed the name of the class or file. When I changed the name, and compiled, i was given this error:

Exception in thread "main" java.lang.NullPointerException
at othello.OthelloEvent.clear_board(OthelloEvent.java:407)
at othello.OthelloEvent.<init>(OthelloEvent.java:441)
at othello.Othello.<init>(Othello.java:22)
at othello.Othello.main(Othello.java:161)

I wasn't sure what to do, as the program had compiled fine just a few minutes earlier, so I updated Netbeans and Java. Once this was done, I found that the original program had developed the same issue! I am by no means an expert in Java, and its probably a mistake I'm making, so any feedback would be helpful. Here is the relevant code:

public void clear_board() 
{
    // go through array and reset buttons and check array
    for (int x = 0; x < 8; x++)
    {
        for (int y = 0; y < 8; y++)
        {
            gui.boxes[x][y].setIcon(gui.back);
            check[x][y] = cell_state.BLANK;
            scores_w[x][y] = 0;
            scores_b[x][y] = 0;
        }
    }

    // set middle pieces
    gui.boxes[3][3].setIcon(a);
    gui.boxes[4][4].setIcon(a);
    check[3][3] = cell_state.WHITE;
    check[4][4] = cell_state.WHITE;
    gui.boxes[4][3].setIcon(b);
    gui.boxes[3][4].setIcon(b);
    check[4][3] = cell_state.BLACK;
    check[3][4] = cell_state.BLACK;

    // reset win and clicks variables, round has been won
    win = 0;
    clicks = 4;
    calc_num_pieces();
}

Thanks in advance for any help!

  • 3
    `at othello.OthelloEvent.clear_board(OthelloEvent.java:407)` which line is 407? Just check at this line with a break point and debugger – TuyenNTA Jun 18 '17 at 01:39
  • 1
    All arrays are not declared and initialized in the method. You should also post the code where they are declared and initialized. – tima Jun 18 '17 at 01:50

0 Answers0