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

2012/1/20

java.lang.IllegalStateException: Actor not in world

Blight Blight

2012/1/20

#
Hi, I'm getting the following 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:656) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860) at Player.checkTeleport(Player.java:198) at Player.act(Player.java:73) at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194) The code looks like this. This is in the act method: if(checkTeleport()) { Greenfoot.playSound("teleport.wav"); setLocation(400, 292); } This is not: public boolean checkTeleport() { Actor teleporter = getOneObjectAtOffset(0, 0, teleporter.class); if(teleporter != null) { return true; } else { return false; } } Anyone got any ideas? Apart from the error message everything works as it should.
danpost danpost

2012/1/20

#
You are probably calling checkTeleport() from the constructor or from outside the Player class or calling another method in the class that calls it. But in anyr case, the Player is not yet in the world and you cannot check for object at offset with getOneObjectAtOffset(int, int, class) until the Player is in the world.
Blight Blight

2012/1/20

#
The code is IN the Player class. if(checkTeleport()) { Greenfoot.playSound("teleport.wav"); setLocation(400, 292); } This code is in the Player class act method. The player should be in the world cause else the code wouldn't even start. How should I fix this ?
davmac davmac

2012/1/20

#
Most likely, the Player is removing itself from the world before it calls checkTeleport(). It's hard to say for sure without seeing more of your code (esp. the act() method).
Blight Blight

2012/1/23

#
This is in the Player class act method: public void act() { checkKeyPress(); checkFall(); if(checkTeleport()) { Greenfoot.playSound("teleport.wav"); setLocation(400, 292); } }
davmac davmac

2012/1/23

#
Like I said:
Most likely, the Player is removing itself from the world before it calls checkTeleport(). It's hard to say for sure without seeing more of your code (esp. the act() method).
So, either checkKeyPress() or checkFall() could be doing this.
You need to login to post a reply.