This code is part of an actor from MyWorld:
All of the Objects are removed, so the if statement is run. The filename is correct (I checked like 10 times) but I get an error message every time:
java.lang.NullPointerException
at Ship.act(Ship.java:80)
at greenfoot.core.Simulation.actActor(Simulation.java:604)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:562)
at greenfoot.core.Simulation.runContent(Simulation.java:221)
at greenfoot.core.Simulation.run(Simulation.java:211)
it also worked when I changed the image directly from the constructor of MyWorld. Do any of you know what I might be doing wrong? Thanks in advance
if(isTouching(Pirate.class))
{
isGameOver = true;
this.getWorld().removeObjects(getWorld().getObjects(Pirate.class));
this.getWorld().removeObjects(getWorld().getObjects(Treasure.class));
this.getWorld().removeObjects(getWorld().getObjects(Ship.class));
((MyWorld)this.getWorld()).setBackground("Loosescreen.png");
}
