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

2013/3/18

Error message; java.lang.IllegalStateException: Actor not in world.

ddcook82 ddcook82

2013/3/18

#
The scenario lets me compile it, but when I try to add one of the actors a screen pops up with this message: 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.getX(Actor.java:157) at Animal.atWorldEdge(Animal.java:59) at Kitty.<init>(Kitty.java:40) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at greenfoot.core.Simulation.newInstance(Simulation.java:578) at greenfoot.localdebugger.LocalDebugger$QueuedInstantiation.run(LocalDebugger.java:155) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:465) at greenfoot.core.Simulation.maybePause(Simulation.java:279) at greenfoot.core.Simulation.runContent(Simulation.java:210) at greenfoot.core.Simulation.run(Simulation.java:203) Here is my code. This happened after I added the atWorldEdge method, but I copied it from one of the other actors I have and that one works fine. I don't know what I screwed up.
danpost danpost

2013/3/19

#
It appears you are calling the 'atWorldEdge' method from the 'Kitty' class constructor. There should be no need to call that method from there. No actions should be taking place at this time (your world is still in the process of being created). If you show your 'Kitty' world class code, someone may be able to help you resolve this.
You need to login to post a reply.