Immediately if i start the program, i'll get a error. And i get it at every act.
But the Object, what causes the error isn't existing.
The error I get is:
And that's the class:
And the second problem is that the arrow stops as soon as it is at Edge.
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:681) at greenfoot.Actor.isTouching(Actor.java:943) at Pfeil.act(Pfeil.java:37) 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.*; /** * Write a description of class Pfeil here. * * @author (your name) * @version (a version number or a date) */ public class Pfeil extends Actor { /** * Act - do whatever the Pfeil wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { setLocation(getX(),getY()-13); Wiese w = (Wiese)getWorld(); if(isAtEdge()){ int hp=w.getHP(); if(hp==3){ w.removeObject(w.getH3()); w.minusHP(); } else if(hp==2){ w.removeObject(w.getH2()); w.minusHP(); } else if(hp==1){ w.removeObject(w.getH1()); w.minusHP(); Greenfoot.stop(); } w.removeObject(this); } if(isTouching(Scheibe.class)){ removeTouching(Scheibe.class); w.removeObject(this); } } }