could someone tell me why this is throwing a null pointer I can't figure it outthis is the terminal window
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Object here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Object extends Actor
{
private int x;
private int y;
public Object()
{
}
protected void addedToWorld(World world)
{
}
/**
* Act - do whatever the Object wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(),getY());
}
@Override
public int getX()
{
ScrollActor actor=(ScrollActor)getOneIntersectingObject(ScrollActor.class);
return Math.abs(actor.calcX()-super.getX());
}
@Override
public int getY()
{
ScrollActor actor=(ScrollActor)getOneIntersectingObject(ScrollActor.class);
return Math.abs(actor.calcY()-super.getY());
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ScrollActor here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ScrollActor extends Actor
{
private int speed=10;
public ScrollActor()
{
setImage("Scroll.jpg");
}
/**
* Act - do whatever the ScrollActor wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
scrolling();
getWorld().showText(""+getX(),250,235);
getWorld().showText(""+getY(),250,265);
}
/**
* Tell the scrollActor where and when to move.
*/
private void scrolling()
{
if(Greenfoot.isKeyDown("up")&&getY()<1245)setLocation(getX(),getY()+speed);
if(Greenfoot.isKeyDown("down")&&getY()>-745)setLocation(getX(),getY()-speed);
if(Greenfoot.isKeyDown("right")&&getX()>-745)setLocation(getX()-speed,getY());
if(Greenfoot.isKeyDown("left")&&getX()<1245)setLocation(getX()+speed,getY());
}
/**
* calculate the coord of the new 0 point on the x axis.
*/
public int calcX()
{
return getX()-(getImage().getWidth()/2);
}
/**
* calculate the coord of the new 0 point on the y axis.
*/
public int calcY()
{
return getY()-(getImage().getHeight()/2);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Olam here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Olam extends World
{
private ScrollActor scroller=new ScrollActor();
/**
* Constructor for objects of class Olam.
*
*/
public Olam()
{
super(500, 500, 1,false);
addObject(scroller,250,250);
Greenfoot.start();
}
}
java.lang.NullPointerException at Object.getX(Object.java:39) at Object.act(Object.java:29) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211)
