The title says it all. I'm getting a "Java.Lang.NullPointerException" at line 420 in my "X" class, and at line 12 in my "AlphaStage" class. I don't know what the problem is though; I haven't tried using anything without defining its existence, so I'm at a loss. Could someone point out the problem?
//health is measured based on actor positions on the Y coordinate
//getWorld().getHeight()/2-96 is the top of the health meter
//getWorld().getHeight()/2+82 is the bottom of the health meter
//Spacing between health point actors is 6 cells (pixels)
//X coordinate for all health related actors for X is 30
//Total health is 30 units
int health=getWorld().getHeight()/2-96; <-- This is line 420
int damage=0;
int heal=0;
public void health()
{
if (damage!=0){
for (damage=damage; damage>0; damage--){
if (health<=getWorld().getHeight()/2+82){
health+=6;
List health1=getWorld().getObjectsAt(30,health,Health1.class);
if (! health1.isEmpty()){
Actor Health1 = (Actor) health1.get(0);
if (Health1!=null){
getWorld().removeObject(Health1);
}
}
}else{
die=true;
}
}
}
if (heal!=0){
for (heal=heal; heal>0; heal--){
if (health>=getWorld().getHeight()/2-96){
health-=6;
getWorld().addObject(new Health1(),30,health);
}
}
}
//Other things that kill you
if (getOneObjectAtOffset(0,0,Block.class)!=null){
die=true;
}
if (getY()==getWorld().getHeight()-1){
die=true;
}
if (die==true){
getWorld().removeObject(this);
}
}
public AlphaStage()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
Greenfoot.setSpeed(56);
addObject(new TestOrb(),getWidth()/2,getHeight()/2+50);
addObject(new X(),getWidth()/2,getHeight()/2); <-- This is line 12
createXHealth();
}
Thank you.