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

2012/12/7

IllegalStateException :(

Stormtrooper299 Stormtrooper299

2012/12/7

#
I get the 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:663) at greenfoot.Actor.getObjectsInRange(Actor.java:882) at Towers.act(Towers.java:115) And the code is
 public void act() 
    {
        reloadDelayCount++;
        placing();
        
       Towers t = (Towers) getOneIntersectingObject(Towers.class);
       Enemies e = (Enemies) getOneIntersectingObject(Enemies.class);
        if (t == null && e == null){
        if (Greenfoot.mouseClicked(this))
         {
             if ( placed == false)
             {
             score();
             placed = true;
            }
         }
        }
         if (health <= 0)
         {
             getWorld().removeObject(this);
            }
         if (Enemies.main != null)
         {
        if (Enemies.main.getWorld() != null )
        {
            if (Towers.main != null)
            {
            if (Towers.main.getWorld() != null )
            {
                if (this.main != null)
            {
            if (this.main.getWorld() != null )
            {
           List<Enemies>objects = getObjectsInRange(BulletRange, Enemies.class);
                   if (objects.size() > -1)
                   {
            if (placed == true)
            {
                
            fire();
        }
    }
    }
        }
    }
}
    }
        
    }
}
The error is line 34
 List<Enemies>objects = getObjectsInRange(BulletRange, Enemies.class);
Shoulden't the 'null' statements fix the eroor? Please help!
davmac davmac

2012/12/7

#
At line 20, you remove 'this' object from the world. Once that's done you can't use the getObjectsInRange method. Probably just adding 'return;' after line 20 would fix the problem.
Stormtrooper299 Stormtrooper299

2012/12/7

#
Thanks! Do you mind explaining what the 'return;' does? Because i have no idea and i would like to learn haha
vonmeth vonmeth

2012/12/7

#
It exits out of the act() method. Here is more information in ways 'return' is used.
You need to login to post a reply.