I am getting the error NullPointerException, if the ball is going under 5 / 795. And cant find it.
this is my actor ball:
private int Beschleunigung = 0;
private int H = 1;
private int G = 1;
/**
* Act - do whatever the ball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
schläger();
wand();
speed();
destroy();
}
private void schläger() {
if (isTouching(schläger.class) && H == 1) {
setRotation(180-getRotation()+(Greenfoot.getRandomNumber(10)
-Greenfoot.getRandomNumber(20)));
Beschleunigung = Beschleunigung +1;
H = 0;
G = 1;
}
if (isTouching(schläger_2.class) && G==1) {
setRotation(180-getRotation()+(Greenfoot.getRandomNumber(10)
-Greenfoot.getRandomNumber(20)));
Beschleunigung = Beschleunigung +1;
G = 0;
H = 1;
}
}
private void wand() {
if (isAtEdge()) {
setRotation(360-getRotation());
}
}
private void speed() {
if (Beschleunigung <= 5) {
move(5);
}
if (Beschleunigung > 5) {
move(6);
}
if (Beschleunigung > 10) {
move(7);
}
if (Beschleunigung > 15) {
move(8);
}
if (Beschleunigung > 20) {
move(9);
}
}
private void destroy() {
if (getX() >= 795 && getWorld() != null) {
getWorld().removeObject(this);
getWorld().addObject(new Red_wins(), 400, 300);
Greenfoot.stop();
}
if (getX() <= 5 && getWorld() != null) {
getWorld().removeObject(this);
getWorld().addObject(new Green_wins(), 400, 300);
Greenfoot.stop()
}
}
}

