English 中文(简体)
Jar file resource not available?
原标题:
  • 时间:2009-11-12 18:32:15
  •  标签:
  • jar

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_DialersrcPhone_Dialer.java
C:Phone_DialersrcDir_IconsKey_1_Silver.gif
C:Phone_DialerdistPhone_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_IconsKey_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.

最佳回答

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

问题回答

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.





相关问题
Refactor packages in a Jar

I have a requirement that i need to load two versions of a jar at once. To avoid class path collisions I d like to rename the packages of one of the jars. Then in source you could always easily ...

Directory list of JAR file within classpath

The typically method to reference a file contained with a JAR file is to use ClassLoader.getResource. Is there a way to get the contents of a directory within a JAR files (similar to java.io.File....

Including dependencies in a jar with Maven

Is there a way to force maven(2.0.9) to include all the dependencies in a single jar file? I have a project the builds into a single jar file. I want the classes from dependencies to be copied into ...

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

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

loading from JAR files during deployment vs development

when i am loading some data into my java program, i usually use FileInputStream. however i deploy the program as a jar file and webstart, so i have to use getRessource() or getRessourceAsStream() to ...

热门标签