Hi all. I'm currently trying to create a typing game where words appear on the screen and move towards the player. The player must then type and press enter to remove words from the screen. I am currently stuck trying to get the word typed to match a word displayed on the screen. To try and solve this i have the class which records what the player types (PType) call a method from a word on the screen. This method then determines if what the player types matches a word on the screen.
I keep receiving an error, (java.lang.NullPointerException). THis occurs in the line "aword.checkWord(typing);"
Here is code from a class which records what the player types:
typing is the variable which holds the string the player has typed.
Here is code from the game world:
Here is code from the word displayed on the screen:
if(k.equals("enter"))
{
SSGame ssgame = (SSGame) getWorld();
List<AWord> AwList = ssgame.getObjects(AWord.class);
for (AWord AW : AwList)
{
AWord aword = ssgame.getAword();
aword.checkWord(typing);
}
//AWord aword = ssgame.getAword();
//aword.checkWord(typing);
typing = "";
} private AWord aword;
public AWord getAword()
{
return aword;
} public void checkWord(String Check)
{
if (Check == ID)
{
SSGame ssgame = (SSGame) getWorld();
ssgame.addObject(new Explosion(), getX(), getY());
ssgame.removeObject(this);
}
else
{
//play incorrect sound
}
}


