This site requires JavaScript, please enable it in your browser!
Greenfoot back
KKobra
KKobra wrote ...

2018/4/17

Greenfoot error

KKobra KKobra

2018/4/17

#
I'm trying to kill an enemy when jump on it, with this code public void enemyDie() { Actor player = getOneObjectAtOffset(0, getImage().getHeight()/2, Player.class); if (player!=null) { World myWorld = getWorld(); myWorld.removeObject (this); } } and i'm have this error 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:711) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:913) at FlyingMod.onGround(FlyingMod.java:120) at FlyingMod.checkFall(FlyingMod.java:145) at FlyingMod.act(FlyingMod.java:29) 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) 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:711) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:913) at FlyingMod.onGround(FlyingMod.java:120) at FlyingMod.checkFall(FlyingMod.java:145) at FlyingMod.act(FlyingMod.java:29) 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) 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:711) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:913) at FlyingMod.onGround(FlyingMod.java:120) at FlyingMod.checkFall(FlyingMod.java:145) at FlyingMod.act(FlyingMod.java:29) 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)
danpost danpost

2018/4/17

#
You probably need to insert the following at line 29 in your FlyingMod class (provided you have not edited the code since your posting):
if (getWorld() == null) return;
You need to login to post a reply.