I posted this in a early thread but I wrote the wrong topic. D'oh! So if you see that one disregard.
I keep getting a run time error: actor not in this world. Any idea what I'm doing wrong
Here are my methods in the laser and boss classes:
Laser class method
/**
* Check whether we have hit the Boss.
*/
public void checkBossHit()
{
if (getWorld() == null) return;
Boss boss = (Boss) getOneIntersectingObject(Boss.class);
if (boss != null){
getWorld().removeObject(this);
boss.hitBoss();
}
}
And in the boss class:
public void hitBoss()
{
if (getWorld() == null) return;
if (bossLife <=0)
{
Greenfoot.playSound("Explosion.wav");
Space space = (Space) getWorld();
space.addObject(new Explosion(), getX(), getY());
space.removeObject(this);
Greenfoot.playSound("hooray.wav");
getWorld().removeObjects(getWorld().getObjects(Counter.class));
space.addObject(new Congratulations(), space.getWidth()/2, space.getHeight()/2);
}
bossLife--;
}
Below is the error message. Any help would be appreciated. Thank you!
java.lang.NullPointerException
at Boss.hitBoss(Boss.java:103)
at Laser.checkBossHit(Laser.java:80)
at Laser.act(Laser.java:43)
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.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:663)
at greenfoot.Actor.getOneIntersectingObject(Actor.java:912)
at Laser.checkBossHit(Laser.java:76)
at Laser.act(Laser.java:43)
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 Boss.hitBoss(Boss.java:103)
at Laser.checkBossHit(Laser.java:80)
at Laser.act(Laser.java:43)
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 Boss.hitBoss(Boss.java:104)
at Laser.checkBossHit(Laser.java:80)
at Laser.act(Laser.java:43)
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 Boss.hitBoss(Boss.java:104)
at Laser.checkBossHit(Laser.java:80)
at Laser.act(Laser.java:43)
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 Boss.hitBoss(Boss.java:104)
at Laser.checkBossHit(Laser.java:80)
at Laser.act(Laser.java:43)
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.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:663)
at greenfoot.Actor.getOneIntersectingObject(Actor.java:912)
at Laser.checkBossHit(Laser.java:75)
at Laser.act(Laser.java:43)
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.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:663)
at greenfoot.Actor.getOneIntersectingObject(Actor.java:912)
at Laser.checkBossHit(Laser.java:75)
at Laser.act(Laser.java:43)
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.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:663)
at greenfoot.Actor.getOneIntersectingObject(Actor.java:912)
at Laser.checkBossHit(Laser.java:75)
at Laser.act(Laser.java:43)
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.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:663)
at greenfoot.Actor.getOneIntersectingObject(Actor.java:912)
at Laser.checkBossHit(Laser.java:75)
at Laser.act(Laser.java:43)
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 Boss.hitBoss(Boss.java:104)
at Laser.checkBossHit(Laser.java:80)
at Laser.act(Laser.java:43)
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)

