I'm trying to set the ImageIcon for a java application, but when I try to obtain the resource I receive a NullPointerException.
This is the directory structure inside of Netbeans:
- project-name
- resources -images icon.png
- src
- target
Here is the code I'm using to set the ImageIcon:
protected ImageIcon createImageIcon(String path, String description) {
java.net.URL imgURL = getClass().getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
LOG.error("Couldn't find file: " + path);
return null;
}
}
I've inserted the following custom code for the iconImage property in Netbeans:
Form.setIconImage(createImageIcon("/project-name/resources/images/icon.png", "Icon Description").getImage());
Any help is greatly appreciated.