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

2016/10/30

nullpointerexception

Sepho Sepho

2016/10/30

#
java.lang.NullPointerException at NBullet.checkBullet(NBullet.java:45) at NBullet.act(NBullet.java:25)

public class NBullet extends Bullet
{
    public NBullet()
    {
        speed= 50;
       
        
        
    }
    /**
     * Act - do whatever the NBullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        shootingspeed();
        checkBullet();
        
    }    
     public void checkBullet()
    {
       Weapon w = new Weapon();
      
       Zombie z = new Zombie();
        
        
       
        Actor zombie = this.getOneIntersectingObject(Zombie.class);
        if(zombie != null )
        
        {
           
           getWorld().removeObject(this);
            
           
          
           getWorld().removeObject(zombie);
            
          
           
        }
         else if ( getX() <= 0|| getY()==0||getY() == 774)
        {  
              getWorld().removeObject(this);
        }
        
      
        
        
    }
   
    
}
pls help me
danpost danpost

2016/10/30

#
Switch lines 33 and 37. If you remove the actor (line 33), the 'getWorld' method (line 37) will not return the world, but 'null' (no World referenced).
You need to login to post a reply.