Reputation: 8004
Please excuse my limited understanding of Java Webstart as I'm very new into this.
So I got my app working in a JAR file on my computer, using this snippet in a static method (class extends JFrame):
ImageIcon image = new javax.swing.ImageIcon(window.getClass().getResource("/resources/img/loginWindowTop.jpg"));
//ImageIcon image = new ImageIcon(window.getClass().getResource("/resources/img/loginWindowTop.jpg")); // tried this too
JLabel imageLabel = new JLabel(image);
imageLabel.setBounds(rect);
window.add(imageLabel);
It works when launching the app on my computer directly from the JAR file. When testing from the web server with a JNLP file, the app crashes showing this:
java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at gui.LoginWindow.create(LoginWindow.java:42)
at main.Starter.main(Starter.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I would really appreciate if someone could explain what to do. I've searched quite a time on the internet and no solution could help me (yet). I hope it's not because I'm working with a static JFrame (called window in my snippet)?
Upvotes: 0
Views: 960
Reputation: 8004
Thanks to your hints, I finally found a way to do it. As my class LoginWindow is only used in a static way, I had to use
ImageIcon image = new ImageIcon(LoginWindow.class.getResource("/resources/img/loginWindowTop.jpg"));
LoginWindow.getClass() would only work in a non-static way.
Thank you all for your input and I hope this helps other people too!
Upvotes: 0
Reputation: 109603
Open the jar with WinZip or 7Zip and look whether the path is indeed /resources/img/loginWindowTop.jpg
, and that case-sensitive. (Especially the file name should be on the file system in that camel case.) A bit esoteric error would be with class loaders, then you could try instead of window.getClass...
simply getClass...
.
Upvotes: 1