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

2013/11/11

NEED HELP WITH ERROR REMOVING OBJECTS

Prish950 Prish950

2013/11/11

#
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. This is my error after the zombie gets hit by the bullets he dies and i get this error and the game stops :( what can i do?? die code for the zombie. (Kugel = Bullet) public void sterben() { Actor kugel; kugel = getOneObjectAtOffset( 0, 0, Kugel.class); if (kugel != null) { World world; world = getWorld(); world.removeObject(this); world.removeObject(kugel); } }
bourne bourne

2013/11/11

#
Where does sterben() get called from?
Prish950 Prish950

2013/11/11

#
from actor zombie
bourne bourne

2013/11/11

#
From zombie's act method?
Prish950 Prish950

2013/11/11

#
yes exactly
bourne bourne

2013/11/11

#
Can I see the the code for where it is called?
Prish950 Prish950

2013/11/11

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Zombie here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Zombie extends Actor
{
    
    public static int currentZombieX;
    public static int currentZombieY;
    
    
     public static int leben = 100;
    
    
    /**
     * Act - do whatever the Zombie wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       AutoAiming();
       sterben();
        
       currentZombieX = getX();
       currentZombieY = getY();
    }
    
    public void AutoAiming() 
    {
        turnTowards(Roboter.currentX, Roboter.currentY);
        move(1);
    }
    
    public void sterben() 
    {
     
     Actor kugel;  
     kugel = getOneObjectAtOffset( 0, 0, Kugel.class);
     
     if (kugel != null)  
      {  
       World world;  
       world = getWorld();  
       world.removeObject(this);  
       world.removeObject(kugel); 
 
      }
      
    }
    
   
}

bourne bourne

2013/11/11

#
Also it is always nice to know on what line of code the Exception was made on, which can be found in the Exception trace.
bourne bourne

2013/11/11

#
Here you go: sterben(); // may remove from world currentZombieX = getX(); // requires you still be in the world currentZombieY = getY();
danpost danpost

2013/11/11

#
Why are you using 'static' for the fields in the Zombie class?
Prish950 Prish950

2013/11/11

#
ahhh okay thank you :)))
You need to login to post a reply.