I placed in game a bomb, for when the badguy intersects, it would both disappear, and an animation would occured.
Problem is, is a,ways giving me an error, game is always crashing.
I wrote this in the Bomb.class
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class BOmb here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bomb extends badGeral
{
/**
* Act - do whatever the BOmb wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
explodeBad();
}
public void explodeBad()
{
Actor bad3 = getOneIntersectingObject(Bad3.class);
pacWorld pacworld = (pacWorld)getWorld();
if(bad3 != null)
{
getWorld().removeObject(this);
getWorld().removeObject(bad3);
}
}
}
and it gives me this:
java.lang.NullPointerException
at Bomb.explodeBad(Bomb.java:27)
at Bomb.act(Bomb.java:17)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.NullPointerException
at Bomb.explodeBad(Bomb.java:27)
at Bomb.act(Bomb.java:17)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
It seems that it is accusing the removeObject(bad3). What's the problem?

