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

2014/12/5

headache java.lang.NullPointerException

guntur guntur

2014/12/5

#
Idk why everytime, always spawn java.lang.NullPointerException I just want to spawn an image after lose pls, need help.. public void kalah(){ GreenfootImage image; if(getWorld() !=null){ if(getX()<50){ getWorld().removeObject(this); Kalah kalah=new Kalah(); getWorld().addObject(kalah, 500, 300); Greenfoot.stop(); } }
danpost danpost

2014/12/5

#
You cannot execute a method on an object reference that does not contain an object, but contain a 'null' reference. Once you remove 'this' from the world 'getWorld' will return 'null'. Move the 'removeobject(this)' line down past where you use 'getWorld' (before, or after, the 'Greenfoot.stop()' call).
You need to login to post a reply.