.Jar file, created by netbeans doesn't open anymore on windows
For some reason, my application stopped working when I used "clean and b开发者_Go百科uild" at NetBeans and try to run it from dist folder. Application used to open from the jar file, but now it only blinks, and even doesn't give any error messages. Application runs, if I test run it with F6 using NetBeans. Jar file is created by NetBeans, so I guess the manifest should be okay.
Here's the link for the jar file...
Executing the jar in the terminal gives this exception trace:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:155)
at tbs.ImageLoader.loadImage(ImageLoader.java:11)
at tbs.Flag.<init>(Flag.java:21)
at tbs.Model.<init>(Model.java:58)
at tbs.GameView.<init>(GameView.java:33)
at tbs.GUI.<init>(GUI.java:36)
at tbs.Main.main(Main.java:6)
So it looks like you had something like this here:
public Image loadImage(String name) {
return new ImageIcon(getClass().getResource(name));
}
... and the getResource()
method returned null
, which caused the ImageIcon
constructor to throw the Exception.
In line 21 of Flag.java you used "images/flagNeutral.png"
as the image string, but your jar file contains images/flagneutral.png
(inside the tbs
directory). See the difference?
If it worked on your local system outside of the jar, you are using a case-insensitive file system there. (Windows or Mac?) In the jar, as well as over HTTP and on "real" file systems, the URLs are case sensitive, which means you have to name the resource precisely as the file is named.
And yeah, normally you should have at least tried your program yourself, and posted the stack trace as well as the relevant code lines.
- There may be a lib folder in the dist directory. If so, it contains jar files for any libraries you included. Make sure that is the case. You need to distribute the jar as well as the entire lib folder and store both in the same folder just like Netbeans creates them.
- I am hoping you have created a Java application project and not a Java Class library project.
- You can check if the main-class attribute and any library paths are added properly when you "clean and build" the project.
- You can run it like
java -jar tbs.jar
and see the response.
Typical error when you don't define the main class before clean and run.
Click right on the project -> properties ->run section ->define the main class.
精彩评论