开发者

Jar file resource not available?

My program has the following lines, works fine when run from Netbeans,

JButton Button_1=new JButton(new ImageIcon(Phone_Dialer.class.getResource("Dir_Icons/"+"Key_1"+Botton_Color+".gif")));

But when I run it from the resulting Jar file, this line caused "java.lang.NullPointerException" error, why ?

The dir is like this :

C:\Phone_Dialer\src\Phone_Dialer.java
C:\Phone_Dialer\src\Dir_Icons\Key_1_Silver.gif
C:\Phone_Dialer\dist\Phone_Dialer.jar

=========================================================================================== It's definitely not the "Botton_Color" problem, It's a string like this : "Silver" or "Pink", so if I change the above line to "Dir_Icons\Key_1_Silver.gif", it still works fine in the IDE while not be able to run from an executable Jar file, the problem seems to be : Why after jar the project, it can't find the resources. The Jar file was generated by Netbeans, and is execu开发者_运维百科table.


It might be a good idea to familiarize yourself with the debugger that comes with your IDE. It will allow you step through, which can be really helpful with debugging little problems like this where you might not expect a variable to be null. Since there is no stack trace, I'd guess Botton_Color is null. Also, it's spelled wrong.


I got it, somehow the sound file suffix is in uppercase, now I changed them to lowercase and it's working, thanks !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜