【发布时间】:2020-03-03 13:24:21
【问题描述】:
我有一个非常简单的构造函数,在其中我将 BooleanProperty 类型的二维数组初始化为全假。但是,我在grid[i][j].set(false) 行收到了 NullPointerException。我不确定为什么会这样,因为grid 不为空?我想我一定是错误地使用了 BooleanProperty,但我不确定为什么。
public class Game {
private BooleanProperty[][] grid;
public Game() {
grid = new BooleanProperty[10][10];
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
grid[i][j].set(false);
}
}
}
// other methods
}
【问题讨论】:
-
grid[i][j] = new BooleanProperty() ?
标签: java javafx constructor