I've posted this question before and Danpost was kind enough to send me an answer, but I'll be honest, I didn't understand it.
Here's what I'm trying to do:
Hero wanders around world for a bit. After a certain number of steps, he encounters an enemy. I've created a class called "BattleBackDrop" which will add all of the necessary objects and control the flow of the battle, and it is at this moment that I am stuck.
The "BattleBackDrop" (bbd for short) can be called from another class easily and added to the world, but I'm trying to get the bbd to add buttons to the world with which the player can control the battle.
But as danpost pointed out to me earlier, I'm trying to call an object into the world by using an object that's not yet in the world, which is backfiring. Is there a way to do this?
Here is the relevant code:
And the actual error is here:
java.lang.NullPointerException
at BattleBackdrop.<init>(BattleBackdrop.java:16)
at Scroller.beginBattle(Scroller.java:158)
at Scroller.checkKeyPress(Scroller.java:83)
at WorldMap.act(WorldMap.java:15)
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)
I'm probably just screwing everything up, but as it turns out, designing a battle system is FAR beyond this hopeless noob.
public BattleBackdrop() { //places the battle backdrop on the world. setImage(img); //error occurs below getWorld().addObject(button, 650, 200); }