Hey Guys,
I have a BIG problem.
Say that I have a cat called cat1. cat1 gets hurt if it falls over an edge (I know, irony). cat1 has a health variable called . There is a class called catHealth display with the code:
The text class extends Actor and declares some colors using java.awt.Color. The cat has a that returns cat1Health. When I run this code i get a java.lang.NullPointerException.
What's the problem???
Thanks in advance,
Samuel.T.Brown
Note:
This is hyperthetical. I am actually creating a game very different to this and I am reluctant to show others the code before I am complete as this is a big project. If it is absolutely neccicary though I will show you my actual code.
public int cat1Health;
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Shows Cats Health
*
* @author SB001 - Samuel.T.Brown
* @version 1.0
*/
public class catHealthDisplay extends text {
private int catsHealth = 1000;
public catHealthDisplay() {
setImage(new GreenfootImage(200, 30));
getHealth();
update();
}
public void update() {
GreenfootImage img = getImage();
img.clear();
img.setColor(gold); //gold is declared in the text class
img.drawString("Cats Health: " + catsHealth, 4, 20);
}
public void getHealth() {
int catsHealth = ((cat1) getWorld().getObjects(cat1.class).get(0)).displayHealth();
}
}public int displayHealth()

