これは私のGridGenerator
クラスにあるコードです。目的は、最終的にマップに結合できる複数の長方形の部屋を作成することです。
int xRange, yRange;
//constructor
public GridGenerator(int xInput, int yInput) {
xRange = xInput;
yRange = yInput;
}
int[][] grid = new int[yRange][xRange];
//the first number indicates the number of rows, the second number indicates the number of columns
//positions dictated with the origin at the upper-left corner and positive axes to bottom and left
void getPosition(int x, int y) {
int position = grid[y][x]; //ArrayIndexOutOfBoundsException here
System.out.println(position);
}
これは私のMapperMain
クラスにあるコードです。目的は、GridGenerator
インスタンスをマルチルーム マップに結合することです。今のところ、デバッグと足場の目的にも使用しています。
public static void main(String[] args) {
GridGenerator physicalLayer1 = new GridGenerator(10,15);
physicalLayer1.getPosition(0, 0); //ArrayIndexOutOfBoundsException here
}
ArrayIndexOutOfBoundsException エラーが発生しています。ある時点で、 にxRange
は 10 の値が割り当てられ、yRange
15 の値が割り当てられます。クラスに値を割り当てても、問題はないようです。クラスでコンストラクターを使用すると、このエラーが発生します。xRange
yRange
grid
xRange
yRange
GridGenerator
MapperMain