Hi guys,
please help me find the error in my code. I get a null pointer exception error every time the bomb reaches the left edge.
Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /* *each time a bomb approaches the left edge of the World it disappears, a new bomb is added to the right edge of the World *and the counter is raised by 1 */ public void removeBomb() { TurtleWorld turtleWorld = (TurtleWorld) getWorld(); if ( getX() <= turtleWorld.getWidth() -turtleWorld.getWidth() + 10 ) { turtleWorld.removeObject( this ); turtleWorld.addObject( new Bomb(), turtleWorld.getWidth() - 10 , Greenfoot.getRandomNumber( turtleWorld.getHeight() ) ); turtleWorld.getCounter().add( 1 ); } } |