I am trying to get an image from the resource folder of my java application. However, no matter in which way I try to get the resource, it gives me a NPE.
This is my code:
JLabel lbl_pic;
ImageIcon i = new ImageIcon(getClass().getClassLoader().getResource("res/img/user.png")); //NPE occurres here
lbl_pic = new JLabel(i);
My NetBeans project folder looks like this:
ProjectName
>Source Packages
>com.scfa.projectName
>main.java
>com.scfa.projectName.res.img
>user.png
Can somebody please tell me, what I have done wrong?
I already looked at the following topics, but couldn't get it working:
- How to correctly get image from 'Resources' folder in NetBeans
- https://docs.oracle.com/javase/tutorial/deployment/webstart/retrievingResources.html
Thanks a lot for your help i advance :)