JAVA: How to find a specific object in array matching certain criteria?

I'm trying to find a certain block from my Block object Array by using the X, and Y specified from the UI. I have been using a locator array making duplicate entries alongside the main array in order to try this.

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

This however spits back an java.lang.ArrayIndexOutOfBoundsException: -1/

It seems like it would work but am I overlooking something?

This is the Error Returned

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)

Answers


Need Your Help

WPF Binding to variable / DependencyProperty

c# wpf xaml binding dependency-properties

I'm playing around with WPF Binding and variables. Apparently one can only bind DependencyProperties. I have come up with the following, which works perfectly fine:

Android thermometer

android battery temperature

Is it possible to implement a thermometer in Android? How?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.