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

2013/11/19

Null Pointer Error Help ?

Prish950 Prish950

2013/11/19

#
i have some Problems with an Error Code!
java.lang.NullPointerException
	at ZombieSpawnSystem.toteZombies10(ZombieSpawnSystem.java:39)
	at ZombieSpawnSystem.act(ZombieSpawnSystem.java:21)
This is my Code at the zombieSpawnSystem class:
public class ZombieSpawnSystem extends Actor
{
    
    public void act() 
    {
        
        if(this !=null)
        {
            spawn(); 
            toteZombies10();
        }   
    }    
    
    public void spawn() 
    {
        if(Greenfoot.getRandomNumber(100) == 1)
        {
            getWorld().addObject(new Zombie(), Greenfoot.getRandomNumber(getWorld().getWidth()), 0);
        }   
    }   
    
    public void toteZombies10() 
    {
        
        if(Zombie.toteZombies == 10)
        {
            getWorld().removeObject(this);
            getWorld().addObject(new ZombieSpawnSystem2(), 437, 212);
        }   
    }   
    
    
}
Please Help me to fix the code and don't get the error :)))
danpost danpost

2013/11/19

#
Line 27 uses 'getWorld' AFTER line 26 remove the actor from the world and therefore will return 'null'. Switch the two lines so it returns the world the object is in before it is removed from that world.
Prish950 Prish950

2013/11/19

#
Thanks very much :))) it works !!
You need to login to post a reply.