Null Pointer Exception on a 2D array (Java)
- by user315156
I have a class, "Tetris", in which one of the instance variables is "board". "board" is 2D array of Color objects. Upon the creation of a tetris object I call a method that sets the dimensions of board and then sets all of the Color objects to be the Default value, that is to say, Color.blue.
public Tetris(int rows, int cols){
this.rows = rows;
this.cols = cols;
reset(rows, cols);
}
public void reset(int rows, int cols){
Color[][] board = new Color[rows][cols];
for(int i = 0; i
Unfortunately, when I run the code (which obviously has not been posted in its entirety) I get a null pointer exception on the line:
board[i][j] = DEFAULT_COLOR; // Color.blue; //DEFAULT-COLOR.
Is there anything obviously wrong with what I am doing?
(Sorry if there are glaring format issues, this is my first time on Stack Overflow)