I'm designing a Tetris game in Gridworld. Below is the method that produces the error. It is a method of the Block class, which is a collection of Actors on which move and rotate methods can be called.
myBlocks
is an ArrayList of BlockSections.
public boolean canMoveDown() {
Grid<Actor> g = myBlocks.get(0).getGrid();
for (BlockSection b : myBlocks) {
Location l = b.getLocation().getAdjacentLocation(180); // Error occurs here
System.out.print(l);
Actor bs = g.get(l);
// Checks if a section of the block is at the bottom of grid,
// and then whether, if there is a block below, if it is not
// part of the current block floating down.
if (b.getLocation().getRow() == 19 || (bs != null && myBlocks.indexOf(bs) == -1))
return false;
}
return true;
}
}
}
I tried inserting a print statement to make sure Location is not null (which it shouldn't be, because all BlockSections being checked are in the grid) and it confirmed that the value was not null. However, the error continues to be generated. Help?
Thanks