My game
I need help with this java exception. In Greenfoot the problem does not appear.
The link above shows my game which throws the error.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import greenfoot.*; public class MyWorld extends World { public static Counter counter; public static void addScore( int score) { counter.add(score); } public MyWorld() { super ( 600 , 400 , 1 ); if (counter == null ) { counter = new Counter(); } addObject(counter, 521 , 27 ); counter.setValue( 0 ); addObject( new You(), 36 , 374 ); for ( int i= 0 ; i< 10 ; i++) { int randomX = 10 + Greenfoot.getRandomNumber( 580 ); int randomY = 1 + Greenfoot.getRandomNumber( 320 ); addObject( new PlasticBottle(), randomX, randomY); } } } |
1 2 3 4 | for ( int i= 0 ; i< 10 ; i++) { addBottle(); } |
1 2 3 4 5 6 | public void addBottle() { int randomX = 10 + Greenfoot.getRandomNumber( 580 ); int randomY = 1 + Greenfoot.getRandomNumber( 320 ); addObject( new PlasticBottle(), randomX, randomY); } |