I'm receiving a run time error called "java.lang.NullPointerException" I'm not really sure what I've done wrong or how I can fix it. The error window pointed out some lines in my code, which I'll write below. I'm making a quiz where you drag buttons with the answers on them to the correct spot on the screen. I thought it would be most efficient to have a button superclass that held the methods each button will use and the common variables they share.
public class MyWorld extends World
{
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
createAnswerBank();
}
/**
* Create a list of formulas to fill the answer bank.
*/
private void createAnswerBank()
{
int x = 7*getWidth()/8;
int y = 14*getHeight()/125;
int z = 7*getHeight()/125;
One one = new One();
addObject(one, x, y+z*Greenfoot.getRandomNumber(16));
}
}
public class Button extends Actor
{
public int intialHeight = world.getHeight()/10;
}
public class One extends Button
{
public void act()
{
checkAnswer(intialHeight);
}
