So I the app lets a user place down blocks on a grid, if the user lines up 3 or more blocks with the same suit, or color, then something happens. When player places a block I call this method:
blocks_.add(new Block(new Vector2(rect_mouse.x, rect_mouse.y), blocks_.get(0).blockID, blockCount));
When you place 3 or more together I call these methods:
blocks_.removeValue(blocks_.get(left_bravo_indexNum), true);
blocks_.removeValue(blocks_.get(center_charlie_indexNum), true);
blocks_.removeValue(blocks_.get(right_alpha_indexNum), true);
stack:
Exception in thread "LWJGL Application" java.lang.IndexOutOfBoundsException: 13
at com.badlogic.gdx.utils.Array.get(Array.java:125)
at com.jrp.mygearapp.GameScreen.touchUp(GameScreen.java:1443)
at com.badlogic.gdx.backends.lwjgl.LwjglInput.processEvents(LwjglInput.java:297)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:186)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
This was intended to remove the blocks, but it resulted in this IndexOutOfBoundsException. Is there a way to prevent this error?
This could be occurring because the array auto sorts the number of elements and lowers the number to the correct number of elements in the array, and I still have elements that are labeled higher then the size of the array. I am still a novice, so my analysis could be incorrect. Please alert me if this is the case and help me find a fix.
Thanks.
edirted* TouchUp() function-------
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
if (button == 0) {
display_blockCheck = false;
////set blockCount to the size of blockArray so blocks can properly be indexed
blockCount = blocks_.size;
if (!overlap) {
Gdx.app.log("Block Added", "x: " + x + " y: " + y);
updateQueueBlocks();
//add block
Vector2 rect_vector = new Vector2(rect_mouse.x, rect_mouse.y);
Block block = new Block(rect_vector,blocks_.get(0).blockID, blocks_.size);
blocks_.add(block);
if (center_charlie_suit == "Square") {
center_charlie_bool = true;
if (right_bravo_suit == "Square") {
right_bravo_bool = true;
if (right_alpha_suit == "Square") {
Gdx.app.log("3-pair", "Square:345:lr");
right_alpha_bool = true;
//call 3-pair event
blocks_.removeValue(blocks_.get(center_charlie_indexNum), true);
blocks_.removeValue(blocks_.get(right_alpha_indexNum), true);
blocks_.removeValue(blocks_.get(right_bravo_indexNum), true);
}
}
}
the rest is just really long and just checks for other blocks next to each other..
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…