i really don't know about this , i have another greenfoot Object with the same code , and it works.
but this code somehow didn't work in my new project , please help
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:695)
at greenfoot.Actor.getX(Actor.java:157)
at Bullet.atWorldEdge1(Bullet.java:54)
at Bullet.checkout1(Bullet.java:47)
at Bullet.act(Bullet.java:22)
at greenfoot.core.Simulation.actActor(Simulation.java:594)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Bullet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bullet extends WorldEdge
{
/**
* Act - do whatever the Bullet wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(10);
destroy();
checkout1();
}
private void destroy()
{
Actor rock = getOneIntersectingObject(Rock.class);
if(getWorld() != null && rock != null)
{
World myWorld = getWorld();
myWorld.removeObject(rock);
myWorld.removeObject(this);
return;
}
}
public void checkout1()
{
if (this.atWorldEdge1() ) {
getWorld().removeObject(this);
return;
}
}
public boolean atWorldEdge1()
{
if(getWorld() != null && getX() < 0 || getX() > getWorld().getWidth() - 0)
return true;
if(getWorld() != null && getY() < 0 || getY() > getWorld().getHeight() - 0)
return true;
else
return false;
}
}


