Results 1 to 3 of 3
- 12-28-2011, 07:42 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 20
- Rep Power
- 0
Some "special gif file" couldn't load from my jar file
Hi Guys,
I continue my GUI application, which contains more images. (antecedent: http://www.java-forums.org/new-java/...-jar-file.html)
After running my application I packaged it to a jar file. Here is my output on the console:
jar -cvf TestJar.jar TestJar.class images
added manifest
adding: TestJar.class(in = 1248) (out= 777)(deflated 37%)
adding: images/(in = 0) (out= 0)(stored 0%)
adding: images/bell.gif(in = 592) (out= 478)(deflated 19%)
adding: images/drum.gif(in = 617) (out= 511)(deflated 17%)
adding: images/Pluto3.gif(in = 2159) (out= 2122)(deflated 1%)
adding: images/reindeer.gif(in = 600) (out= 587)(deflated 2%)
adding: images/santa-hat.gif(in = 597) (out= 500)(deflated 16%)
adding: images/skate.gif(in = 359) (out= 349)(deflated 2%)
And now I noticed, I have some special image files which couldn't load from the jar file.
For example pluto3.gif, I enclosed it with my code. What could be the difference between that file and the others ?
I think the file size wouldn't be cause of my problem.
Maybe It has got a special inner structure which differs from the others ? Or it would be a performance problem, and my computer is not too fast?
I enclosed my all image files, they are placed in the images subdirectory which is on the same level with the class file.
Any idea would be greatly appreciated!
Thanks
Here is my code:
Java Code:import javax.swing.*; import java.awt.Graphics; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; public class TestJar extends JPanel{ public void paintComponent(Graphics g) { BufferedImage image; try{ // I comment the images which works fine /* image = ImageIO.read(getClass().getResource("/images/bell.gif")); g.drawImage(image,20,20,this); image = ImageIO.read(getClass().getResource("/images/drum.gif")); g.drawImage(image,20,60,this); image = ImageIO.read(getClass().getResource("/images/reindeer.gif")); g.drawImage(image,20,140,this); image = ImageIO.read(getClass().getResource("/images/skate.gif")); g.drawImage(image,20,180,this); */ //this file doesn't want to load image = ImageIO.read(getClass().getResource("/images/pluto3.gif")); g.drawImage(image,20,220,this); } catch(java.io.IOException ioe) { ioe.printStackTrace(); } } public static void main(String[] args) { TestJar tj = new TestJar(); JFrame frame = new JFrame("Merry Christmas..."); frame.getContentPane().add(tj); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600,800); frame.setVisible(true); } }
- 12-28-2011, 08:02 PM #2
Re: Some "special gif file" couldn't load from my jar file
What is different from the 4 statements that work and the one that does not work?
Are you sure the image is in the jar file in the correct location. It should be in the same folder as the images that you can read.
Have you spelled the name correctly?
- 12-28-2011, 08:41 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Similar Threads
-
Couldn't load my image from the jar file
By Zamioculcas in forum New To JavaReplies: 8Last Post: 12-30-2011, 04:54 PM -
"java.io.FileNotFoundException" occurs eventhough file present in location
By shibusbtn in forum Advanced JavaReplies: 6Last Post: 04-05-2011, 11:33 AM -
Getting access denied error while importing file using input type="file" with IE7
By sarang1 in forum Advanced JavaReplies: 6Last Post: 02-10-2011, 10:55 AM -
Exception in thread "main" java.io.FileNotFoundException: reverse.dat (No such file o
By erin.ctm in forum New To JavaReplies: 4Last Post: 11-06-2010, 12:50 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 08:35 AM
Bookmarks