Question: how would i fix this error: Exception in thread main java.lang.NullPointerException: Cannot read the array length because tictactoegame.TicTacToeGame.gameboard is null at TicTacToeGame / tictactoegame .

how would i fix this error:
"Exception in thread "main" java.lang.NullPointerException: Cannot read the array length because "tictactoegame.TicTacToeGame.gameboard" is null
at TicTacToeGame/tictactoegame.TicTacToeGame.displayBoard(TicTacToeGame.java:18)
at TicTacToeGame/tictactoegame.TicTacToeGame.main(TicTacToeGame.java:49)"
package tictactoegame;
public class TicTacToeGame {
static int[][] gameboard;
static final int EMPTY =0;
static final int NOUGHT =-1;
static final int CROSS =1;
/* Set a square on the board must be empty */
public static void set(int val, int row, int col) throws IllegalArgumentException {
if (gameboard[row][col]== EMPTY)
gameboard[row][col]= val;
else throw new IllegalArgumentException("Player already there!");
}
/* display the board */
public static void displayBoard(){
for(int r=0; r

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!