whenever bullet hits the tank . Everything stop i don't know why. can you help me please?
at greenfoot.core.Simulation.run(Simulation.java:183) java.lang.NullPointerException at Bullet.checkTankHit(Bullet.java:43) at Bullet.act(Bullet.java:21) at greenfoot.core.Simulation.actActor(Simulation.java:567) at greenfoot.core.Simulation.runOneLoop(Simulation.java:530)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bullet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bullet extends Actor
{
private static final int damage =15;
/**
* Act - do whatever the Bullet wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(), getY()+1);
explosion();
if(getWorld()!=null) checkTankHit();
}
private void explosion()
{
if(isAtEdge()){
getWorld().removeObject(this);
}
}
/**
* Check whether enemy bomb hit our tank or not
*/
private void checkTankHit(){
Tank tank =(Tank) getOneIntersectingObject(Tank.class);
if (tank != null)
{
getWorld().removeObject(this);
Background background = (Background)getWorld();
background.addScore(15);
}
}
}
