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

2020/3/14

null pointer exception

yeeterboi420 yeeterboi420

2020/3/14

#
so basically I'm working on this for school for a project and whenever a laser hits an apple, the terminal window pops up and I get a message saying null pointer exception on my laser. The specific line is getWorld().getObjects(Laser.class) != null && shouldBeRemoved() and shouldBeRemoved(): public boolean shouldBeRemoved(){ // checks boundaries boolean checkY = getY() - getImage().getHeight()/2 < 0; System.out.println(checkY); if(checkY == true){ return true; } return false; } and I don't know why I'm getting the exception. Can anyone help me?
yeeterboi420 yeeterboi420

2020/3/14

#
like as an if statement so if(getWorld().getObjects(Laser.class) != null && shouldBeRemoved()){ //code }
danpost danpost

2020/3/14

#
Is it possible the actor is not in the world when this code is executed (that is, getWorld() is returning a null value)?
You need to login to post a reply.