Here is my code:
Within the if statement, I made it so if you click the "start game" image it would remove it.
Afterward, I tried adding an object into the world (a Golbat) which has an image of a Golbat
Then I get an error within my terminal window saying:
I know I'm definitely pulling a beginner mistake, so when I click the "start game" image, how would I add a Golbat image in the middle of the world screen?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class StartGameButtonGuessThatPokemon here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class StartGameButtonGuessThatPokemon extends Actor
{
GreenfootSound who = new GreenfootSound("Who's that Pokemon.mp3");
/**
* Act - do whatever the StartGameButtonGuessThatPokemon wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
startGame();
}
public void startGame()
{
if(Greenfoot.mouseClicked(this))
{
who.play();
getWorld().removeObjects(getWorld().getObjects(StartGameButtonGuessThatPokemon.class));
getWorld().addObject(new Golbat(),getWorld().getWidth()/2,getWorld().getHeight()/2);
}
}
}
java.lang.NullPointerException at StartGameButtonGuessThatPokemon.startGame(StartGameButtonGuessThatPokemon.java:27) at StartGameButtonGuessThatPokemon.act(StartGameButtonGuessThatPokemon.java:18)

