I have an app that runs fine when I am not attempting to use it as a web start app, but when I convert it to one in Netbeans, it goes belly up. The console is showing a null pointer exception when trying to get a resource that is located in a dependent library. The line of code itself grabs a .png file in that library file and uses it for the window icon. The lines of code that kill it is:
java.net.URL url = ClassLoader.getSystemResource("/com/my/icon/someimage.png");
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.createImage(url); // fails with null pointer exception
If I am not trying to do this as a web start app then I have zero issues. It runs perfectly. Web start = failboat. The code is signed, if that makes any difference. The library file that is being used is one large jar that contains 3 library files I created plus 4 others that are needed which I did not code myself. Do I need to sign the library file as well? Is this possibly an issue in and of itself?
EDIT:
If I take out those lines of code, the web app runs without any issues.
Here is the error:
Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at sun.net.util.URLUtil.getConnectPermission(Unknown Source)
at sun.awt.SunToolkit.checkPermissions(Unknown Source)
at sun.awt.SunToolkit.createImage(Unknown Source)
at DDSC.initComponents(DDSC.java:265)
at DDSC.<init>(DDSC.java:103)
Try using getClassLoader().getResource() with just the filename.
Full path isn't required and getClassLoader() handles the magic via WebStart & also locally:
String filename = "someimage.png";
Image resultImg = null;
URL url = getClassLoader().getResource(filename);
if (url != null)
resultImg = Toolkit.getDefaultToolkit().getImage(url);