I get the error
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.getObjectsInRange(Actor.java:882)
at Towers.act(Towers.java:115)
And the code is
The error is line 34
Shoulden't the 'null' statements fix the eroor?
Please help!
public void act() { reloadDelayCount++; placing(); Towers t = (Towers) getOneIntersectingObject(Towers.class); Enemies e = (Enemies) getOneIntersectingObject(Enemies.class); if (t == null && e == null){ if (Greenfoot.mouseClicked(this)) { if ( placed == false) { score(); placed = true; } } } if (health <= 0) { getWorld().removeObject(this); } if (Enemies.main != null) { if (Enemies.main.getWorld() != null ) { if (Towers.main != null) { if (Towers.main.getWorld() != null ) { if (this.main != null) { if (this.main.getWorld() != null ) { List<Enemies>objects = getObjectsInRange(BulletRange, Enemies.class); if (objects.size() > -1) { if (placed == true) { fire(); } } } } } } } } }
List<Enemies>objects = getObjectsInRange(BulletRange, Enemies.class);