Im doing a city builder and i get a NullPointerException when i want to add money to my bank. The counter Bank has the name Geld. I want that the objekt Wolke adds money to my bank when i press "right". Heres my World called Menue:
hers the code of the class Wolke:
Im a beginner and i looked at many other forum posts but i couldnt find anything and now the code might look messy.
public class Menue extends World
{
private Counter geld;
/**
* Constructor for objects of class Menue.
*
*/
public Menue()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1000, 750, 1);
menuebalken();
Knoepfe();
SZaehler();
Wolke();
//einkommen();
}
public void SZaehler() {
Counter geld = new Counter();
addObject(geld,250, 40);
}
public void Wolke() {
Wolke wolke = new Wolke();
addObject(wolke, 195,140);
}
public Counter gibgeld() {
return geld;
}public class Wolke extends Zaehler
{
public void act()
{
if (Greenfoot.isKeyDown("right")) {
if (getWorld() !=null){
Menue menue = (Menue)getWorld();
menue.gibgeld().add(1);
}
}
}
