Java I';我在做一个塔防游戏,我';我创建了一个TileGrid类,但它给了我一个OBB异常(ArrayIndexOutOfBounds)

Java I';我在做一个塔防游戏,我';我创建了一个TileGrid类,但它给了我一个OBB异常(ArrayIndexOutOfBounds),java,Java,我正在制作一个塔防游戏,我已经添加了一个TileGrid类来用草填充整个地图,但是它在TileGrid.java:12抛出/给出了一个OBB异常。它使用LWJGL OpenGL 代码如下: package JosephJoshua.TowerDefense; import JosephJoshua.TowerDefense.main.Tile; public class TileGrid { public Tile[][] map; public TileGrid() {

我正在制作一个塔防游戏,我已经添加了一个TileGrid类来用草填充整个地图,但是它在TileGrid.java:12抛出/给出了一个OBB异常。它使用LWJGL OpenGL

代码如下:

package JosephJoshua.TowerDefense;

import JosephJoshua.TowerDefense.main.Tile;

public class TileGrid {
    public Tile[][] map;

    public TileGrid() {
        map = new Tile[20][15];
        for (int i = 0; 1 < map.length; i++) {
            for (int j = 0; j < map[i].length; j++) {
                map[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Grass);
            }
        }
    }
    public void draw() {
        for(int i = 0; 1 < map.length; i++) {
            for(int j = 0; j < map[i].length; j++) {
                map[i][j].draw();
            }
        }
    }
}
包裹Josephua.TowerDefense;
导入josephua.TowerDefense.main.Tile;
公共类瓦莱格里德{
公共地砖[]地图;
公共TileGrid(){
地图=新瓷砖[20][15];
对于(int i=0;1
尝试更改

for (int i = 0; 1 < map.length; i++)
for(int i=0;1

for(int i=0;i

在循环结束时继续执行i++操作,因此最终会得到超出数组边界的索引

1
?应该是
i
它仍然在第18oh行上给我一个OBB异常,我将它改为for(Tile[]行:map){for(Tile-Tile:row){Tile.draw();}}很好!我必须看这两行大约30秒才能注意到区别。
for (int i = 0; i < map.length; i++)