With the developing of my game, I'm having problem adding a class (the image of that class ), when an intersection happens...
It crashes and gives me this error:
public class theBomb extends pacActors
{
pacWorld pacworld = (pacWorld)getWorld();
//Smoke smoke = (Smoke)pacworld.getObjects(Smoke.class).get(0);
Smoke smoke = new Smoke();
/**
* Act - do whatever the theBomb 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 bad = getOneIntersectingObject(Bad.class);
Actor bad1 = getOneIntersectingObject(Bad1.class);
Actor bad2 = getOneIntersectingObject(Bad2.class);
Actor bad3 = getOneIntersectingObject(Bad3.class);
Actor bad4 = getOneIntersectingObject(Bad4.class);
Actor bad5 = getOneIntersectingObject(Bad5.class);
Actor bad6 = getOneIntersectingObject(Bad6.class);
pacWorld pacworld = (pacWorld)getWorld();
//int x = getX();
//---------------ao intersectar, remove a bomba e o bad
if(bad != null)
{
pacworld.removeObject(bad);
pacworld.removeObject(this);
}
if(bad1 != null)
{
pacworld.removeObject(bad1);
pacworld.removeObject(this);
}
if(bad2 != null)
{
pacworld.removeObject(bad2);
pacworld.removeObject(this);
}
if(bad3 != null)
{
pacworld.removeObject(bad3);
addSmoke();
pacworld.removeObject(this);
}
if(bad4 != null)
{
pacworld.removeObject(bad4);
pacworld.removeObject(this);
}
if(bad5 != null)
{
pacworld.removeObject(bad5);
pacworld.removeObject(this);
}
if(bad6 != null)
{
pacworld.removeObject(bad6);
pacworld.removeObject(this);
}
}
public void addSmoke()
{
for(int x = getX(); x < 28; x++)
{
pacworld.addObject(new smokeBomb(), x, getY());
smoke.vanish(40);
}
}
}
java.lang.NullPointerException at theBomb.addSmoke(theBomb.java:86) at theBomb.explodeBad(theBomb.java:58) at theBomb.act(theBomb.java:20) 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)
