Applet wont run from Jar file

I created a jar file that contains the applet.class and the Image directory and the sound directory. I extracted the file and everything was present and looked correct.

The console shows that it loaded the images and sounds, but all I get is a black screen.

If I unarchive the jar and try the applet again, it loaded properly.

I tried jarring the data compressed, uncompressed with the -C option for relative path(?). Nothing worked.

Do I need to load the images in the applet.java code differently if using a jar file as the end deployment means?

Also the Manifest file only contains the following info…
Manifest-Version: 1.0
Created-By: 1.6.0_10 (Sun Microsystems Inc.)
Isnt the manifest supposed to show a file list?

Thanks for any help

[quote]Do I need to load the images in the applet.java code differently if using a jar file as the end deployment means?
[/quote]
Yes, try:
BufferedImage image = ImageIO.read(ImageLoader.class.getResourceAsStream(filename));

You can use this simple image loader if you want to. http://www.java-gaming.org/index.php/topic,20634.0.html

I do really appreciate the help!

well, as ridiculous as this is (3rd party loader just to load applet images from a jar), I tried…

butLPass = ImageLoader.loadImage(“images/buttons/”,“butPassL2.gif”);
Got an error of
Error loading: /images/buttons/butPassL2.gif
java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at ImageLoader.loadImg(ImageLoader.java:33)
at ImageLoader.loadImage(ImageLoader.java:25)
at NMHearts.init(NMHearts.java:126)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

and

butLPass = ImageIO.read(ImageLoader.class.getResourceAsStream(“images/buttons/butPassL2.gif”));
Cant remember if I got an error, too tired to retype the code.

I did run the applet without the jar and it worked fine using both methods described above. I dont understand this mess.

Also tried this, as suggested from http://www.rgagnon.com/javadetails/java-0240.html


public void Init(){
     butLPass = setImage("/images/buttons/butPassL2.gif");
}

public Image setImage(String tPath){
     int i = 0;
     Image tImg = null;
     try{
	InputStream is = getClass().getResourceAsStream(tPath);
	BufferedInputStream bis = new BufferedInputStream(is);
	byte[] byBuf = new byte[100000]; 
	int byteRead = bis.read(byBuf,0,100000);
	tImg = Toolkit.getDefaultToolkit().createImage(byBuf);
	i = 1;
     }
     catch(Exception e){
	System.out.println("setImage Error: "+e);
     }

     return tImg;
}

It works without the Jar again but gives a “setImage Error: java.io.IOException: Stream closed” error when trying to pull the Images from the jar file.

Also tried copying all images to the root folder create a jar like so…

jar cvf NMHearts.jar NMHearts.class *.gif *.png

The output from the command screen looks fine.

Launch it from an html page that looks like so…


<HTML>
<HEAD>
<TITLE>HEARTS!</TITLE>
</HEAD>
<p>
<applet code ="NMHearts.class" 
	archive="NMHearts.jar"
	width=670 height=500>
</APPLET>
<P>
</HTML>

Still no luck, the console shows all images loaded, but they dont display on the applet, the game works fine, If I click where the buttons should be, the game works, any printed text shows up, etc. Just the images dont display.

Unfrickin real!

You could try opening the jar with a zip program to make sure all the files are where they should be. Might add System.out.println(“drawing image”); where you are drawing the images.

I have verified the contents by extracting, viewing in winzip, changing the archive to a zip and referencing that in the html file (as suggested by other forums, didnt work). Everything checked out ok in the archive.

Also tried…


   	public Image setImages(String tPath){
   		//URL base = getDocumentBase();
   		//= getImage(base,"imageExample.gif");
  
		URL imageLocation = getClass().getResource(tPath);
		Image img = getImage(imageLocation);
		
		return img;
   	}

To no avail. I give up. Ill try a simpler applet and go from there next time. It could be due to the paint() method, reading the file in an image instead of buffered image trough a stream instead of file access, or something in between. I really appreciate the help.