I have recently been programming a platforming game in java, and I have run into a problem when I tried to use a separate class to store my map (tiled). I then tried to fix it by moving the map into the main class, and it didn't help.
This is the code that is causing the problem (When the world.map1.render(0,0) is removed, no problem exists) - I know that I should be using getters and setters. I'm just find them a pain.
public void render(GameContainer arg0, Graphics arg1) throws SlickException {
world.map1.render(0, 0);
}
this is the main method
public static void main(String[] args) throws SlickException{
AppGameContainer app = new AppGameContainer(new Game());
app.setDisplayMode(864, 480, false);
app.setVSync(true);
app.start();
playerSheet = new SpriteSheet("resources/images/link3goldstudmod.png", 64, 64);
player = new Player(playerSheet);
world = new World();
}
and this is the World class
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;
public class World {
TiledMap map1;
World() throws SlickException{
map1 = new TiledMap("resources/maps/map1.tmx");
}
}
EDIT: I forgot to post the problem/stack crap/whatever. How silly of me.
Mon Feb 18 16:33:58 MST 2013 INFO:Slick Build #264
Mon Feb 18 16:33:58 MST 2013 INFO:LWJGL Version: 2.8.5
Mon Feb 18 16:33:58 MST 2013 INFO:OriginalDisplayMode: 1920 x 1080 x 32 @60Hz
Mon Feb 18 16:33:58 MST 2013 INFO:TargetDisplayMode: 864 x 480 x 0 @0Hz
Mon Feb 18 16:33:58 MST 2013 INFO:Starting display 864x480
Mon Feb 18 16:33:58 MST 2013 INFO:Use Java PNG Loader = true
WARNING: Found unknown Windows version: Windows 8
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
Mon Feb 18 16:33:59 MST 2013 INFO:Found 3 controllers
Mon Feb 18 16:33:59 MST 2013 INFO:0 : USB Receiver
Mon Feb 18 16:33:59 MST 2013 INFO:1 : USB Receiver
Mon Feb 18 16:33:59 MST 2013 INFO:2 : Logitech Speaker
Mon Feb 18 16:33:59 MST 2013 ERROR:null
java.lang.NullPointerException
at zeldaplatform.Game.render(Game.java:36)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:703)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at zeldaplatform.Game.main(Game.java:27)
Mon Feb 18 16:33:59 MST 2013 ERROR:Game.render() failure - check the game code.
org.newdawn.slick.SlickException: Game.render() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:706)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at zeldaplatform.Game.main(Game.java:27)
It's not much of an error, because it compiles just fine, and then the console gives me this. The window shows up for a split second, and then disappears.