Using a 2D Array in a Class Object - NullPointerException?

Sorry … I used the wrong verbiage.

You need to allocate them in the constructor using the new keyword.

class Level {
boolean[][] my2dArr; // declare

Level(int arg1, int arg2) {
my2dArr = new boolean[arg1][arg2];  // allocate

my2dArr[0][0] = true; // define
}
1 Like