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

2017/12/10

Object not found

Simon1122111 Simon1122111

2017/12/10

#
in the picture you can see my problem. when my object is between x = 582 and x = 585 the game crashes and the 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:711) shows up. please help me.
danpost danpost

2017/12/10

#
Simon1122111 wrote...
when my object is between x = 582 and x = 585 the game crashes
The problem is not in the code given in the image. It stems from your act method, maybe to a previously called method (previous to the call to the first method in the image).
Simon1122111 Simon1122111

2017/12/10

#
danpost wrote...
Simon1122111 wrote...
when my object is between x = 582 and x = 585 the game crashes
The problem is not in the code given in the image. It stems from your act method, maybe to a previously called method (previous to the call to the first method in the image).
but if it is between but if i type : between x=212 and x = 116 it works perfect.
Simon1122111 Simon1122111

2017/12/10

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Player here. * * @author (your name) * @version (a version number or a date) */ public class Player extends Actor { /** * Act - do whatever the Player wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { checkKey(); collisionStraßenrand(); } private void checkKey() { if (Greenfoot.isKeyDown("a")) { setLocation(getX()-4, getY()); } if (Greenfoot.isKeyDown("d")) { setLocation(getX()+4, getY()); } if (Greenfoot.isKeyDown("w")) { setLocation(getX(), getY()-5); } if (Greenfoot.isKeyDown("s")) { setLocation(getX(), getY()+4); } } private void collisionStraßenrand() { if (getX() >= 582 && getX() <= 585) { explodiere(); } if (getX() >= 212 && getX() <= 217) { explodiere(); } } public void explodiere() { Explosion explosion1 = new Explosion(); getWorld().addObject( explosion1 , getX() , getY()); getWorld().removeObjects(getWorld().getObjects(Player.class)); } } this is my source code and it only crashes if my actor is between 582 and 585
danpost danpost

2017/12/10

#
Simon1122111 wrote...
it only crashes if my actor is between 582 and 585
Oh, sorry -- it is in that code given, then. Add the following second line after the first instance of the first line:
explodiere();
return;
Simon1122111 Simon1122111

2017/12/10

#
okay it works. thank you!
You need to login to post a reply.