I’ve recently tried to set my default application icon with a .ico file I made myself. This is the code I used to create the icon:
initComponents();
java.net.URL url = ClassLoader.getSystemResource("/src/calculatormedii/resources/CMedii.ico");
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.createImage(url);
getFrame().setIconImage(img);
I have no idea why it’s so difficult to set the java desktop application icon in netbeans, it should just be a property field like the rest.
When I try to run the program, these errors show up:
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:99)
at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:113)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:240)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
No idea what to do now. If there is an alternate way to set the application icon please specify it (Like a property field in netbeans or something)
I strongly suspect it’s the URL you’re using. Using
ClassLoader.getSystemResource, you shouldn’t need a leading slash – but I very much doubt that you want thesrcpart either. You should make sure that your icon is copied to the same place that your class files is (e.g. abindirectory) and then just use: