Once again, for the crude minesweeper game I'm making, I'm trying to make the thing that removes adjacent tiles of the same bomb value. I have a function that checks all adjacent tiles for their value, runs this function in that tile, then deletes itself. It compiles, but when I click on a tile, I get this error:
java.lang.NullPointerException
at Square.revealTiles(Square.java:33)
at Square.revealTiles(Square.java:34)
at Square.revealTiles(Square.java:34)
at Square.revealTiles(Square.java:34)
at Square.revealTiles(Square.java:34)
at Square.revealTiles(Square.java:34)
at Square.revealTiles(Square.java:34)
at Square.revealTiles(Square.java:34)
at Square.revealTiles(Square.java:34)
at Square.revealTiles(Square.java:34)
at Square.revealTiles(Square.java:34)
at Square.revealTiles(Square.java:34)
The code for the function is as follows:
Normally, when you run function on another object and you do the object. all of the completions inherited from actor class are there but they arent just the ones Ive made.
public void revealTiles() {
for (int xO = 0; xO <= 2; xO++) {
for (int yO = 0; yO <=2; yO++) {
Numbers nNumber = (Numbers)getOneObjectAtOffset(xO - 1, yO - 1, Numbers.class);
Square nSquare = (Square)getOneObjectAtOffset(xO - 1, yO - 1, Square.class);
Numbers tNumber = (Numbers)getOneIntersectingObject(Numbers.class);
if (nNumber.numberOfBombs() == tNumber.numberOfBombs()) {
nSquare.revealTiles();
}
}
}
getWorld().removeObject(this);
}


Currently I have it set to only make 1 bomb.
It seems like Greenfoot doesn't delete objects until all of the other code has finished running, making it add all of those squares to all of the list and then deleting them, causing to to try to delete things that have already been deleted.