MCVE
import Green.*;
class ExampleActor extends Actor
{
public ExampleActor(float x, float y, int w, int h)
{
super(x, y, w, h); // Line causing error
}
public void act(float deltaTime)
{
}
}
ExampleActor atr = new ExampleActor(1,1,1,1);
Why does this trigger a nullpointer exeption?
This is a pure guess, based on very limited information, but giving values 1,1,1,1 to constructor could break it. It might break some initialization, so try other values especially larger w(idth) and h(eight) values.
just tried 100,100,100,100 (it didn’t work.) it’s even weirder.
what if x,y and w and h have different value, like (10,10,30,30)?
just tried 10,20,30,40. nope!
What does documentation tell you?
Constructor and Description
Actor(float x, float y, int w, int h)
Creates the new actor at a position with a defined width and height.
from Actor (Javadocs: Green)
Something else is missing then. Perhaps you need to create world object first for actor to reside in?
public abstract class World
extends java.lang.Object
The base class for all worlds in the library. A world is it's own area for a collection of Actor instances to interact in, though any given Actor can be within multiple worlds at a time. Only one world may be active at a time however, which can be changed by calling Green.loadWorld(World).
as i feared, it gets an error while creating the world.
import Green.*;
class ExampleActor extends World
{
public ExampleActor()
{
super(); // Line causing error
}
public void act(float deltaTime)
{
}
public void prepare()
{
}
}
ExampleActor atr = new ExampleActor();
UPDATE: wait, new ExampleActor();
causes the error? i got rid of it and it worked flawlessly!