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

2013/11/2

Someone know how to catch this?

ddvink ddvink

2013/11/2

#
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 Mob.checkFloor(Mob.java:51) at RibbonPig.changeDirectionCheck(RibbonPig.java:117) at RibbonPig.act(RibbonPig.java:111) 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)
ddvink ddvink

2013/11/2

#
This is the code that belongs to it
  public boolean checkFloor()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int)(spriteHeight/2);

        Platform floor = (Platform)getOneObjectAtOffset( 0, yDistance, Platform.class);

        if(floor != null && floor.getMostOutside()){
            return true;
        } else {
            return false;
        }
    }
danpost danpost

2013/11/2

#
The error occurs in 'checkFloor', but the cause of the error is probably found in your 'act' method (the order in which you call your methods. You probably have a method that removes the actor from the world before calling the 'checkFloor' method; hence, causing the error. You could probably add a line into your act before the call to 'checkFloor':
// in the act method
if (getWorld() == null) return; // insert this line
checkFloor();
You need to login to post a reply.