java - Map render error slick2d -
i have been programming platforming game in java, , have run problem when tried utilize separate class store map (tiled). tried prepare moving map main class, , didn't help.
this code causing problem (when world.map1.render(0,0) removed, no problem exists) - know should using getters , setters. i'm find them pain.
public void render(gamecontainer arg0, graphics arg1) throws slickexception { world.map1.render(0, 0); }
this 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 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: forgot post 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 utilize 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 @ zeldaplatform.game.render(game.java:36) @ org.newdawn.slick.gamecontainer.updateandrender(gamecontainer.java:703) @ org.newdawn.slick.appgamecontainer.gameloop(appgamecontainer.java:456) @ org.newdawn.slick.appgamecontainer.start(appgamecontainer.java:361) @ zeldaplatform.game.main(game.java:27) mon feb 18 16:33:59 mst 2013 error:game.render() failure - check game code. org.newdawn.slick.slickexception: game.render() failure - check game code. @ org.newdawn.slick.gamecontainer.updateandrender(gamecontainer.java:706) @ org.newdawn.slick.appgamecontainer.gameloop(appgamecontainer.java:456) @ org.newdawn.slick.appgamecontainer.start(appgamecontainer.java:361) @ zeldaplatform.game.main(game.java:27)
it's not much of error, because compiles fine, , console gives me this. window shows split second, , disappears.
it's nullpointerexception
. there exactly 1 cause npe; thing attempting utilize not instantiated , null
. in case, that's either world
in game
class or map1
in world
class.
considering instantiate new game
@ start of game.main()
, start it, , proceed assign new world
static
field of said class (you don't post game
class, that's way main()
, stack trace shows it's game.main()
), it's former.
appgamecontainer
(app
) beingness fired start()
, thread proceeds phone call instance of game
's render()
method before have instantiated , assigned world
static field.
don't utilize static
fields that; it's not for. should passing instances (playersheet
, player
, , world
) constructor of game
, assigning them private instance variables.
... game mygame = new game(playersheet, player, world); appgamecontainer app = new appgamecontainer(mygame); ...
java lwjgl slick2d slick
No comments:
Post a Comment