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

2016/3/26

I keep getting this error...

IanWasHere IanWasHere

2016/3/26

#
I don't know how to fix it... When my ball hits the bottom of the screen it says this... I need help. 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:695) at greenfoot.Actor.getOneIntersectingObject(Actor.java:942) at Ball.checkBlock(Ball.java:81) at Ball.act(Ball.java:36) 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)
remy88 remy88

2016/3/26

#
Whenever you get an error, Greenfoot is pretty helpful about it, you just have to read and debug. From that statement above, it says "Actor not in world". This probably means you tried to do something with your ball before it was actually put on the screen. Perhaps you need to use addedToWorld(World world) method of the Actor. In order to be more specific of what you are doing wrong, you will need to post code. When you see the error, a few of those lines should be highlighted red, and should allow you to click on it. When you click on it the line of the error should highlight. That line will be the problem. Either post that code, or try to debug it.
Super_Hippo Super_Hippo

2016/3/26

#
Since the error happens in the checkBlock-method which is called by the act-method, the object was already in the world, but got removed. Somewhere in your code, you have this line:
1
getWorld().removeObject(this);
After this line, avoid to use any method which requires the object to be in the world.
IanWasHere IanWasHere

2016/3/26

#
Super_Hippo wrote...
Since the error happens in the checkBlock-method which is called by the act-method, the object was already in the world, but got removed. Somewhere in your code, you have this line:
1
getWorld().removeObject(this);
After this line, avoid to use any method which requires the object to be in the world.
Ok, I'll try it. If not I will post some code! Thanks!
IanWasHere IanWasHere

2016/3/26

#
It didn't work... Here's the code: /** * Check whether we have hit a block, and make the block disappear if we have. */ private void checkBlock() { Actor block = getOneIntersectingObject(Block.class); if (block !=null) { deltaY = -deltaY; getWorld().removeObject(block); counter.addScore(); } }
IanWasHere IanWasHere

2016/3/26

#
/** * Check whether we're out (bottom of screen). */ private void checkOut() { if (getY() == getWorld().getHeight()-1) { ((Board) getWorld()).ballIsOut(); getWorld().removeObject(this); } }
IanWasHere IanWasHere

2016/3/26

#
This piece of code is highlighted: : Actor block = getOneIntersectingObject(Block.class); But I need this piece of code... without it, my game doesn't work...
danpost danpost

2016/3/26

#
Move the call to 'checkOut' to the end of 'act'.
You need to login to post a reply.