In making a quiz, when the the flag of a country (an image) is collided with the wrong answer (another image) the the flag reaches at its starting position. I have used setLocation for that in the following way.
But if I collide with the correct answer I am facing the terminal window.
This is the code that I used to do some thing when I collide with the right and the wrong answer.
This is the terminal error that I get.
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.isTouching(Actor.java:925)
at UaeFlag.act(UaeFlag.java:32)
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)
Please help me with the alterations I can make to make it right.
setLocation(1204, 114);
if(isTouching(Blank1.class))
{
getWorld().removeObject(this);
}
if(isTouching(Blank2.class) || isTouching(Blank3.class) || isTouching(Blank4.class) || isTouching(Blank5.class) || isTouching(Blank6.class))
{
setLocation(1204, 114);
}