This is related to a bird game. if the player (the bird) eats a food object, the game stops. I would like the game to keep running.
This is what is displayed:
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:663)
at greenfoot.Actor.getOneObjectAtOffset(Actor.java:867)
at Food.EatenbySmallBird(Food.java:44)
at Food.act(Food.java:22)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
This the code it is related to:
public void EatenbySmallBird()
{
Actor SmallBird = getOneObjectAtOffset(0, 0, SmallBird.class); // looks at the birds location
if(SmallBird != null) {
getWorld().removeObject(this); //if bird touches the food then it become null
}
}


