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

2018/4/13

NullPointerException error even precautionary if statement and multiple instances of class in the world. (ma boi danpost help me out)

maboidanpost maboidanpost

2018/4/13

#
public void movementmodi(int movepov,int ym, int moveneg, int yp){ if(Station.level>0){ if(time==30){ move(movepov); if(getWorld().getObjects(Zako.class)!=null){ setLocation(getX(),getY()-ym); } getImage().scale(40,35); } if(time==60){ move(moveneg); if(getWorld()!=null&&getWorld().getObjects(Zako.class)!=null){ setLocation(getX(),getY()+yp); } getImage().scale(35,30); } } } java.lang.NullPointerException at line 51 LINE 51 IS: if(getWorld().getObjects(Zako.class)!=null){.....]
Yehuda Yehuda

2018/4/13

#
It would be easier if you posted the output from the terminal window and the entire (Ctrl+A) class code with code tags (see below). With the (amount of) code that you showed I don't see anything wrong, I can only guess that maybe you're getting a NullPointerException because you're trying to call getWorld() when the actor has been removed from the World.
danpost danpost

2018/4/13

#
You did not check for getWorld not be return null first like you did on line 58.
You need to login to post a reply.