I am currently working on a project, using two actor classes (let's call them classA and classB).
The project contains a world class (here: worldclass) with the following constructor...
...that works perfectly fine.
In classA, the constructor contains...
...which produces 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."
I think I know what it means: this command cannot be executed as the classA-object to which getX()/getY() refers to doesn't exist.
However, I've always thought that the constructor of a actor class is executed whenever an object of this class is added to the world.
Therefore, the object of classA should exist (as it is inserted via the constructor of the worldclass), and the coordinates should be found by the programm - but obviously it's not working.
Moreover, if I replace getX/getY by int-values, the programm states
"java.lang.NullPointerException"
I am aware that the command getWorld().addObject...does work in classA when executed in any method.
Does anyone know why it doesn't in a class constructor (for both error messages)?
Thanks in advance
1 2 3 4 5 | public worldclass () { addObject ( new classA(), 20 , 200 ); } |
1 2 3 4 | public classA() { getWorld().addObject( new classB(), getX(), getY()); } |