I recieve with following code an null pointer exeception why?
Can anyone help me?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Die Klasse MyKara ist eine Unterklasse von Kara.
* Sie erbt damit alle Methoden der Klasse Kara:
*
* Aktionen: move(), turnLeft(), turnRight(), putLeaf(), removeLeaf()
* Sensoren: onLeaf(), treeFront(), treeLeft(), treeRight(), mushroomFront()
*/
public class MyKara extends Kara
{
/**
* In der Methode 'act()' koennen die Befehle fuer Kara programmiert werden.
* Die Befehle werden dort nacheinander aufgerufen, wenn man nach dem
* 'Uebersetzen' (=kompilieren) den 'Act'-Knopf drueckt.
* Beim druecken des 'Run'-Knopfes wird diese Methode immer wieder ausgefuehrt.
*/
public void bewegen(int x)
{
if(getX() != x - 1 && Greenfoot.isKeyDown("left"))
{
turnLeft();
if(canMove())
{
move();
}
turnRight();
}
if(getX() != x - 1 && Greenfoot.isKeyDown("right"))
{
turnRight();
if(canMove())
{
move();
}
turnLeft();
}
}
BeweglicherTree treeTree = new BeweglicherTree();
public void act()
{
while(!treeFront())
{
bewegen(getX());
treeTree.baumAct(getX());
}
}
} import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class BeweglicherTree extends Actor
{
public void beweglicheBäume(int xx)
{
int anzahlBeweglicherBäume = 5;
Tree treeB[] = new Tree[anzahlBeweglicherBäume];
for(int i = 0; i < anzahlBeweglicherBäume; i++)
{
treeB[i] = new Tree();
}
Baum baum[] = new Baum[anzahlBeweglicherBäume];
baum[0] = new Baum(2, 9);
/*baum[1] = new Baum(2, 3);
baum[2] = new Baum(2, 5);
baum[3] = new Baum(2, 7);
baum[4] = new Baum(2, 9);*/
boolean karaVormBaum = false;
do
{
for(int a = 0; a < anzahlBeweglicherBäume; a++)
{
karaVormBaum = false;
if(baum[a].getLocationY() >= -1 && baum[a].getLocationY() <= 25)
{
if(baum[a].getLocationX() + 1 == xx)
{
karaVormBaum = true;
}
if(baum[a].getLocationY() >= 0)
{
getWorld().removeObject(treeB[a]);
}
baum[a].setLocation(baum[a].getLocationX(), baum[a].getLocationY() + 1);
if(baum[a].getLocationY() <= 25)
{
getWorld().addObject(treeB[a],baum[a].getLocationX(),baum[a].getLocationY());
}
}
}
}while(!karaVormBaum);
}
public void baumAct(int xx)
{
beweglicheBäume(xx);
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Baum here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Baum extends Actor
{
int xK;
int yK;
public Baum(int xK, int yK)
{
this.xK = xK;
this.yK = yK;
}
public int getLocationX()
{
return xK;
}
public int getLocationY()
{
return yK;
}
public void setLocationY(int y, int x)
{
this.xK = x;
this.yK = y;
}
}
