tags:

views:

79

answers:

3

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 executable.

A: 

What is Botton_Color? Perhaps that is null? Do you have a full stack trace?

Boiler Bill
A: 

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.

Chris Lacasse
A: 

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

Frank