Hello Guys,
I seem to have a problem with my code everytime it is started:
It keeps giving me this error:
java.lang.IllegalStateException: Actor has been removed from the world.
at greenfoot.Actor.failIfNotInWorld(Actor.java:722)
at greenfoot.Actor.isTouching(Actor.java:987)
at Bullet.movement(Bullet.java:40)
at Bullet.act(Bullet.java:24)
at greenfoot.core.Simulation.actActor(Simulation.java:567)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:530)
at greenfoot.core.Simulation.runContent(Simulation.java:193)
at greenfoot.core.Simulation.run(Simulation.java:183)
Caused by: greenfoot.ActorRemovedFromWorld
at greenfoot.World.removeObject(World.java:466)
at Bullet.movement(Bullet.java:36)
... 5 more
java.lang.IllegalStateException: Actor has been removed from the world.
at greenfoot.Actor.failIfNotInWorld(Actor.java:722)
at greenfoot.Actor.isTouching(Actor.java:987)
at Bullet.movement(Bullet.java:40)
at Bullet.act(Bullet.java:24)
at greenfoot.core.Simulation.actActor(Simulation.java:567)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:530)
at greenfoot.core.Simulation.runContent(Simulation.java:193)
at greenfoot.core.Simulation.run(Simulation.java:183)
Caused by: greenfoot.ActorRemovedFromWorld
at greenfoot.World.removeObject(World.java:466)
at Bullet.movement(Bullet.java:36)
It might be to do with my bullet code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public Bullet()
{
}
public void act()
{
movement();
}
private void movement()
{
move(6);
if (isAtEdge())
{
World world = getWorld();
if(world != null)
{
world.removeObject(this);
}
}
if(isTouching(Zombies.class))
{
Counter counter = (Counter) getWorld().getObjects(Counter.class).get(0);
counter.add(1);
}
}
}
Do you know how I can fix this?