I'm trying to lower the enemy's health everytime the laser hits it but i keep getting an error:
java.lang.NullPointerException
at Laser.destroy(Laser.java:120)
at Laser.act(Laser.java:33)
at greenfoot.core.Simulation.actActor(Simulation.java:565)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:523)
at greenfoot.core.Simulation.runContent(Simulation.java:213)
at greenfoot.core.Simulation.run(Simulation.java:203)
my laser class is this:
Actor BossWall = getOneIntersectingObject(BossWall.class);
public void destroy()
{
if(BossWall != null)
{
BossWall wall = (BossWall) getOneObjectAtOffset(0, 0, BossWall.class);
unlock = true;
explodeAlien.play();
if(wall.checkH()==0)
{
getWorld().removeObject(BossWall);
}
wall.health(-1);
getWorld().removeObject(this);
}
}
Can i get some help please?
I think its the way im using my wall.checkH() method is an accessor so i assumed that how it should look