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.
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).
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.
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