This site requires JavaScript, please enable it in your browser!
Greenfoot back
tost1
tost1 wrote ...

2012/4/15

I need HELP FAST !!!

tost1 tost1

2012/4/15

#
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 DelfinLinks.eat(DelfinLinks.java:43) at DelfinLinks.act(DelfinLinks.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 HaiLinks.eatFischKlein1(HaiLinks.java:55) at HaiLinks.act(HaiLinks.java:22) 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 HaiLinks.eatFischKlein1(HaiLinks.java:55) at HaiLinks.act(HaiLinks.java:22) 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) Delfin.class : DelfinRechts public void act() { move(); eat(); eat2(); } public void move() { int xpos = getX() + 2; if (xpos >= 899) { getWorld().removeObject(this); } else { setLocation(xpos, getY()); } } public void eat() { Actor HaiRechts; HaiRechts = getOneObjectAtOffset(0, 0, DelfinRechts.class); if(HaiRechts != null) { World world; world = getWorld(); world.removeObject(HaiRechts); } } public void eat2() { Actor HaiLinks; HaiLinks = getOneObjectAtOffset(0, 0, DelfinRechts.class); if(HaiLinks != null) { World world; world = getWorld(); world.removeObject(HaiLinks); } } } DelfinLinks public void act() { move(); eat(); eat2(); } public void move() { int xpos = getX() - 2; if (xpos <= 1) { getWorld().removeObject(this); } else { setLocation(xpos, getY()); } } public void eat() { Actor HaiRechts; HaiRechts = getOneObjectAtOffset(0, 0, DelfinLinks.class); if(HaiRechts != null) { World world; world = getWorld(); world.removeObject(HaiRechts); } } public void eat2() { Actor HaiLinks; HaiLinks = getOneObjectAtOffset(0, 0, DelfinLinks.class); if(HaiLinks != null) { World world; world = getWorld(); world.removeObject(HaiLinks); } } } Hai.class: public class HaiLinks extends Actor { /** * Act - do whatever the Hai wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveAround(); eatFischKlein1(); eatFischKlein2(); eatFischOrangeRechts(); eatFischOrangeLinks(); eatFischGelbLinks(); eatFischGelbRechts(); eatSeepferdchenLinks(); eatSeepferdchenRechts(); } public void moveAround() { int xpos = getX() - 2; if (xpos <= 1) { getWorld().removeObject(this); } else { setLocation(xpos, getY()); } } public void eatFischKlein1() { Actor FischKleinLinks; FischKleinLinks = getOneObjectAtOffset(0, 0, HaiLinks.class); if(FischKleinLinks != null) { World world; world = getWorld(); world.removeObject(FischKleinLinks); } } public void eatFischKlein2() { Actor FischKleinRechts; FischKleinRechts = getOneObjectAtOffset(0, 0, HaiLinks.class); if(FischKleinRechts != null) { World world; world = getWorld(); world.removeObject(FischKleinRechts); } } public void eatSeepferdchenRechts() { Actor SeepferdchenRechts; SeepferdchenRechts = getOneObjectAtOffset(0, 0, HaiLinks.class); if(SeepferdchenRechts != null) { World world; world = getWorld(); world.removeObject(SeepferdchenRechts); } } public void eatSeepferdchenLinks() { Actor SeepferdchenLinks; SeepferdchenLinks = getOneObjectAtOffset(0, 0, HaiLinks.class); if(SeepferdchenLinks != null) { World world; world = getWorld(); world.removeObject(SeepferdchenLinks); } } public void eatFischGelbLinks() { Actor FischGelbLinks; FischGelbLinks = getOneObjectAtOffset(0, 0, HaiLinks.class); if(FischGelbLinks != null) { World world; world = getWorld(); world.removeObject(FischGelbLinks); } } public void eatFischGelbRechts() { Actor FischGelbRechts; FischGelbRechts = getOneObjectAtOffset(0, 0, HaiLinks.class); if(FischGelbRechts != null) { World world; world = getWorld(); world.removeObject(FischGelbRechts); } } public void eatFischOrangeRechts() { Actor FischOrangeRechts; FischOrangeRechts = getOneObjectAtOffset(0, 0, HaiLinks.class); if(FischOrangeRechts != null) { World world; world = getWorld(); world.removeObject(FischOrangeRechts); } } public void eatFischOrangeLinks() { Actor FischOrangeLinks; FischOrangeLinks = getOneObjectAtOffset(0, 0, HaiLinks.class); if(FischOrangeLinks != null) { World world; world = getWorld(); world.removeObject(FischOrangeLinks); } } public void eat() { Actor Fisch; Fisch = getOneObjectAtOffset(0, 0, HaiLinks.class); if(Fisch != null) { World world; world = getWorld(); world.removeObject(Fisch); } } } what is false i need help please
danpost danpost

2012/4/15

#
In your act() method, the first thing you did, was to call move(). In move(), there is a possibility that 'this' object will be removed from the world. Then, when it returns back to act(), you call eat() and eat2(), which both use 'getOneObjectAtOffset'. If move() did remove the 'this', then 'getOneObjectAtOffset' will throw the IllegalStateException call (you cannot get an offset from something that is NOT in the world). Therefore, after your move() call in act(), insert the line
if (getWorld() == null) return;
This will avoid eat() and eat2() from executing if 'this' was removed from the world.
tost1 tost1

2012/4/15

#
thank you :)
You need to login to post a reply.