私は次のコードを持っています:
public class GameCanvas extends JPanel {
private GridField[][] grid;
private int x, y;
private int fieldSize;
public GameCanvas(int rows, int cols, int fieldSize)
{
this.grid = new GridField[cols][rows];
this.x = cols;
this.y = rows;
this.fieldSize = fieldSize;
}
...
}
GridFieldクラスの定義は次のとおりです。
public class GridField {
private FieldType fieldType;
public GridField() {
fieldType = FieldType.EMPTY;
}
public FieldType getFieldType() {
return fieldType;
}
public void setFieldType(FieldType fieldType) {
this.fieldType = fieldType;
}
}
問題は、「グリッド」オブジェクトにアクセスしようとすると、クラスのコンストラクターで初期化したにもかかわらず、コンパイラーがnullと表示することです。
私は少しチェックしました:
if(grid[xSize][ySize] == null) {
System.out.println("Grid[x][y] is null");
}
それは私が期待したものを正確に印刷しました-null。
私はC#のバックグラウンドからJavaに来ているので、何かを逃したかもしれません。些細な間違いだと思いますが、見つかりません。
ヒントを事前に感謝します。