Can not load the images in Java Swing when running from a .jar-file

Can not load the images in Java Swing when running from a .jar-file

Page 1 of 1

4 Replies - 3020 Views - Last Post: 19 January 2011 - 03:49 AM Rate Topic: -----

#1 kirti.adsul  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 02-November 10

Can not load the images in Java Swing when running from a .jar-file

Posted 12 January 2011 - 03:21 AM

Hi,
I want to load images from one package to another packages but it can't load that in Java Swing when running from a .jar-file

Plz guide me...
Is This A Good Question/Topic? 0
  • +

Replies To: Can not load the images in Java Swing when running from a .jar-file

#2 masijade  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: Can not load the images in Java Swing when running from a .jar-file

Posted 12 January 2011 - 03:45 AM

getResourceAsStream not FileInputStream (if that's what you're doing). In any case, it would probably help to
1. See the code
2. Know the complete path to the jar file
3. Know the complete path to the images
4. Know if the images are located in the jarfile
5. Know the complete package of the class
6. Know the location of the images in relation to the package of the class loading them
Was This Post Helpful? 0
  • +
  • -

#3 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2552
  • View blog
  • Posts: 10,636
  • Joined: 20-September 08

Re: Can not load the images in Java Swing when running from a .jar-file

Posted 12 January 2011 - 03:46 AM

Keep your images in /images and then load thus:


Image i = javax.imageio.ImageIO.read(getClass().getResourceAsStream("/images/x.png"));

Was This Post Helpful? 1
  • +
  • -

#4 kirti.adsul  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 02-November 10

Re: Can not load the images in Java Swing when running from a .jar-file

Posted 19 January 2011 - 03:27 AM

I have made changes but still i am unable to run jar file with image.
Plz guide me
Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2552
  • View blog
  • Posts: 10,636
  • Joined: 20-September 08

Re: Can not load the images in Java Swing when running from a .jar-file

Posted 19 January 2011 - 03:49 AM

Please post

a. Loading code
b. The output of

jar tf yourjar.jar

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1