[英]NullPointerException on exported Slick2D project
My Slick2D project seems to run okay when executed in the Eclipse IDE, but when I export it through JarSplice , it throws a NullPointerException
in the class 'Menu'. 我的Slick2D项目在Eclipse IDE中执行时似乎可以正常运行,但是当我通过JarSplice导出该项目时 ,它会在“菜单”类中引发
NullPointerException
。
Here is the snippet of code that throws the error: 这是引发错误的代码片段:
@Override
public void render( GameContainer gc, StateBasedGame sbg, Graphics g ) throws SlickException {
g.setColor( Color.black );
g.setFont( Options.getGameFont() );
// Draw foreground objects.
{
g.drawString( "Start", 10, gc.getHeight()-50 ); // This line here
}
}
Along with the stack trace: 连同堆栈跟踪:
Sat Apr 18 17:20:59 BST 2015 ERROR:null
java.lang.NullPointerException
at org.newdawn.slick.Graphics.drawString(Graphics.java:1366)
at com.mgthomas.states.Menu.render(Menu.java:48)
at org.newdawn.slick.state.StateBasedGame.render(StateBasedGame.java:199)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:688)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at com.mgthomas.Launch.main(Launch.java:48)
Sat Apr 18 17:20:59 BST 2015 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:691)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at com.mgthomas.Launch.main(Launch.java:48)
I have already added 'slick.jar' and 'lwjgl.jar', as well as all of the windows natives, to JarSplice, and it exports without any problems. 我已经在JarSplice中添加了'slick.jar'和'lwjgl.jar'以及所有Windows本机,并且它导出时没有任何问题。 However, when the exported .jar file is ran through the command prompt, the error above is displayed.
但是,当通过命令提示符运行导出的.jar文件时,将显示以上错误。
(Sorry - I don't have enough reputation points to post a comment so am posting this as an answer.) (对不起-我的信誉度不足,无法发表评论,所以将其发布为答案。)
If you have added the library jars and natives as per the guide below then it should work. 如果您按照以下指南添加了库jar和本机库,则它应该可以工作。
Simple guide to creating a .jar, .exe or .jnlp? 创建.jar,.exe或.jnlp的简单指南?
Which version of Slick2D are you using? 您正在使用哪个版本的Slick2D? I only ask because I recently updated my libraries to the Slick build 237 with LWJGL 2.9.2 version (10 January 2015) and had some issues with it.
我之所以这么问,是因为我最近将我的库更新为LWJGL 2.9.2版本的Slick build 237(2015年1月10日),并且出现了一些问题。 I reverted to the Slick build 237 with LWJGL 2.9.0 (3 June 2013) in the end.
最后,我将LWJGL 2.9.0(2013年6月3日)恢复为Slick build 237。 Even though the build numbers are the same, the issues I had suggested that something had changed in Slick2D and made it unstable.
即使内部版本号相同,但我建议的问题是Slick2D中的某些内容已发生更改并变得不稳定。 I've noted online that others have had problems with that build as well.
我在网上指出,其他人也对该版本有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.