Hey I am receiving this error and I am wondering if anyone can tell me what I am doing wrong. It comes up as soon as I start the game. There isn't any code in the if statements yet but that is on purpose. I do not know what i want to do in the if statements yet. Here is the error and my code for my Ball class.
java.lang.NullPointerException
at Ball.Warning(Ball.java:38)
at Ball.act(Ball.java:22)
at greenfoot.core.Simulation.actActor(Simulation.java:565)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:523)
at greenfoot.core.Simulation.runContent(Simulation.java:213)
at greenfoot.core.Simulation.run(Simulation.java:203)
Here is my code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ball extends Actor
{
private int uSpeed = -8;
private int acceleration = 1;
private int dSpeed = 8;
/**
* 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()
{
move();
Warning();
}
public void move()
{
if(Greenfoot.isKeyDown("up"))
{
setLocation ( getX(), getY() + uSpeed);
}
else
{
setLocation ( getX(), getY() + dSpeed);
}
}
public void Warning()
{
Actor zone = getOneIntersectingObject(Zone.class);
if((zone.getY() - (zone.getImage().getHeight() / 2)) > (getY() + (getImage().getHeight() / 2)))
{
}
if((zone.getY() + (zone.getImage().getHeight() / 2)) < (getY() - (getImage().getHeight() / 2)))
{
}
}
}