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:656)
at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860)
at Lev1.shot(Lev1.java:139)
at Lev1.act(Lev1.java:19)
at greenfoot.core.Simulation.actActor(Simulation.java:507)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:470)
at greenfoot.core.Simulation.runContent(Simulation.java:204)
at greenfoot.core.Simulation.run(Simulation.java:194)
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:656)
at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860)
at Lev1.shot(Lev1.java:139)
at Lev1.act(Lev1.java:19)
at greenfoot.core.Simulation.actActor(Simulation.java:507)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:470)
at greenfoot.core.Simulation.runContent(Simulation.java:204)
at greenfoot.core.Simulation.run(Simulation.java:194)
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:656)
at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860)
at Lev1.shot(Lev1.java:139)
at Lev1.act(Lev1.java:19)
at greenfoot.core.Simulation.actActor(Simulation.java:507)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:470)
at greenfoot.core.Simulation.runContent(Simulation.java:204)
at greenfoot.core.Simulation.run(Simulation.java:194)
Im a bit of a noob at Greenfoot and get this error as soon as the "Boss" shoots me "Lev1" . I checked out a few other posts yet I don't understand them and dont relate to me as much ^_^ This is my code for the "Boss"
@Override
public void setLocation(int x, int y)
{int width = getWorld().getWidth();
int height = getWorld().getHeight();
while (x >= width)
{
x -= width;
}
while (x < 0)
{
x += width;
}
while (y >= height)
{
y -= height;
}
while (y < 0)
{
y += height;
}
super.setLocation(x, y);
}
public void Banana()
{
List objects = getObjectsInRange(100000, Lev1.class);
if (!objects.isEmpty())
{
Lev1 lev1 = (Lev1)objects.get(0);
int distY = lev1.getY() - getY();
int distX = lev1.getX() - getX();
double angleRadians = Math.atan2(distY, distX);
int angleDegrees = (int)Math.toDegrees(angleRadians);
setRotation(angleDegrees);
move(1);
}
}
public void cat()
{
sequence ++;
switch(sequence)
{
case 1: bullet bullet = new bullet();
bullet.turn(180);
getWorld().addObject(bullet, getX(), getY());
bullet.setRotation(getRotation()); break;
case 10: sequence = 0; break;
}
I hope someone can help me fix this error! Thanks for the help! :D

