There was an error trying to open .jpg

Answered

Hello!

I'm having a problem in which my code is unable to open a .jpg file. I honestly have no idea how to fix this - everything I tried wouldn't work. I would greatly appreciate any help!

0
3 comments

You should put images in the resources directory and load them from the classpath instead, see https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html .

0
Avatar
Permanently deleted user

Could you please explain what you mean by that? I don't really understand. 

 

0

Check out this tutorial with the sample code showing how to load images from the classpath: https://examples.javacodegeeks.com/desktop-java/ide/intellij-idea/intellij-idea-gui-designer-tutorial/ .

icon01 = new ImageIcon(getClass().getResource("image01.jpg"));
0

Please sign in to leave a comment.