When I start the program as soon as you hit the first ball the game freezes segnalandomi the following error: java.lang.NullPointerException in the method addScore (). Why? Can anyone help me?
My goal is to change the background after the timer is set to 30sec ends. The background, however, must change only if the score is greater than or equal to a total defined. I can not make it work. If you need more information just ask! thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public void Move(){ if (Bordo()){ /**rimuove i piatteli vicini ai bordi*/ getWorld().removeObject( this ); } else if (Collisione(Proiettile. class )){ /**rimuove gli oggetti colpiti e il proiettile che l'ha c*/ Campo x = (Campo) getWorld(); Actor p = getOneIntersectingObject(Proiettile. class ); getWorld().removeObject(p); getWorld().removeObject( this ); addScore(); } else { /**da una determinata velocità ai piattelli*/ MovePiattello(Greenfoot.getRandomNumber( 5 )+ 3 ); } } |
1 2 3 4 5 6 7 | public void addScore() { if (!getWorld().getObjects(Counter. class ).isEmpty()) { ((Counter) getWorld().getObjects(Counter. class ).get( 0 )).add( 1 ); } } |