Note: I did try out ImageIcon background = new ImageIcon(getClass().getResource("MyImage.jpg"));
mentioned in all the answers.
My project works fine using netbeans IDE run. But once I export to an executable jar using 'Clean and build', A null pointer exception is thrown and the frame with the image will not even open. (The executabe jar is in the 'dist' folder)
Even after using relative path, the image will never load.
- I put the image in same directory as the executable jar.(dist)
- I put the image in the lib folder. (dist\lib)
- I created an src and res folders and put image in those folders.(dist\src & dist\res)
None of the above worked.
I opened the jar with winRar and saw the image is present. but it never loads on running. Can anyone please help me.??