0

My Application uses some images.The application works fine in the Eclipse IDE.Here's the Code Snippet being used :

URL url=screen_one.class.getClassLoader().getResource("./small.png");

JLabel image=new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().getImage(url)));

But when i export it to a jar , it shows Uncaught error fetching Image.I think its related to the path of the image "small.png".

But when i run "jar tvf" with my file name this is the output -

1635 Tue Apr 03 19:53:44 IST 2012 small.png

This suggests the path is correct ; So,Where am i wrong??

Thanks

nikel
  • 3,402
  • 11
  • 45
  • 71

1 Answers1

0

I would put all images in the /src/res folder in order to make sure they are exported properly with your .jar. Also, see this similar question.

Community
  • 1
  • 1
lrAndroid
  • 2,834
  • 18
  • 27
  • No, but I have had problems trying to do it that way. Putting the images in /src/res and accessing them using "/res/icon.png" got it working for me. – lrAndroid Apr 14 '12 at 17:24
  • Well Yeah,that works.Any reason as to why my earlier approach did not work? – nikel Apr 14 '12 at 17:28
  • That does not count as an explanation for this , i think?:-| – nikel Apr 14 '12 at 17:34
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10081/discussion-between-nikel-and-lrandroid) – nikel Apr 14 '12 at 17:46