0

我正在尝试使用从 UI 指定的 X 和 Y 从我的块对象数组中找到某个块。我一直在使用定位器数组在主数组旁边制作重复条目以尝试此操作。

public Block get(int x, int y) {
            int index = 0;
            index = blocks.indexOf(locator[x][y], true);
            return blocks.get(index);
        }

然而,这会吐出一个 java.lang.ArrayIndexOutOfBoundsException: -1/

似乎它会起作用,但我是否忽略了一些东西?

这是返回的错误

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.ArrayIndexOutOfBoundsException: -1
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
    at com.badlogic.gdx.utils.Array.get(Array.java:126)
    at com.myname.javatest.World.get(World.java:80)
    at com.myname.javatest.ui.UserInterface.renderPositions(UserInterface.java:35)
    at com.myname.javatest.screens.GameScreen.render(GameScreen.java:58)
    at com.badlogic.gdx.Game.render(Game.java:46)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:187)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
4

0 回答 0