JAVA:如何在符合特定条件的数组中查找特定对象?

时间:2013-08-22 19:06:24

标签: java arrays contains indexof

我正在尝试使用从UI指定的X和Y从我的Block对象Array中找到某个块。我一直在使用一个定位器阵列在主阵列旁边制作重复的条目,以便尝试这个。

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)

0 个答案:

没有答案