I am Using Windows 10, Apache NetBeans, maven swing project;
maven project structure:
|-- projectname
|-- Source Packages
| |--package1
| |--package2
| |--resources
| | |--images
| | | |--image.png
Though NetBeans displays nested packages/folders like this resources.images
Inside NetBeans, When I right-click on image.png
then click Properties
then click (All Files
...) it gives me this path:
C:\Users\%USERNAME%\Documents\NetBeansProjects\projectname\src\main\java\resources\images\image.png
How to reference image path?
I tried many paths, also many answers from this site, but non solved my problem. The output always gives Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
java.net.URL u = getClass().getResource("/resources/images/image.png");
ImageIcon icon = new ImageIcon(u);
JLabel label1 = new JLabel("Image and Text", icon, JLabel.CENTER);