Hi Greenfoot-Community,
I have a little problem. As the topic says a null pointer exception is triggered, but I can't comprehend why.
Here is the important part:
replacing() is called in the act() method of the world. Everything except the player has to be moved, according to the worldX/Y coordinates. The method isn't finished yet, but as for now, it was working without exceptions,until i put the removeObject part into it. I already used the debugger to see, whether a contains an actor when it enters the if-clause and it does. So why does it throw a nullpointer exception at removeObject?
Thanks for help
Sincerely,
Jimmy
private void replacing() { java.util.List<Actor> actors = getObjects(Actor.class); for(Actor a: actors) { if(!(a instanceof Player)) { if(a.getX() >= getWidth() -30) { worldMap.put((worldMapX + a.getX()) + "#" + (worldMapY + a.getY()),a); System.out.println(a); removeObject(a); }else { a.setLocation(a.getX()+worldX, a.getY()+worldY); } } } }