Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Applet wont run from Jar file  (Read 1250 times)
0 Members and 1 Guest are viewing this topic.
Offline Xyle
« Posted 2009-07-08 02:27:51 »

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

Life is just a game, learn to play!
------------------------------------------
╬-YellzBellz Games!-╬ Cheesy
Offline zoto

Senior Devvie


Medals: 4



« Reply #1 - Posted 2009-07-08 03:13:17 »

Quote
Do I need to load the images in the applet.java code differently if using a jar file as the end deployment means?
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/topics/unsigned-web-start-image-loader/20634/view.html
Offline Xyle
« Reply #2 - Posted 2009-07-08 04:32:25 »

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.

Life is just a game, learn to play!
------------------------------------------
╬-YellzBellz Games!-╬ Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Xyle
« Reply #3 - Posted 2009-07-08 05:08:25 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
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.

Life is just a game, learn to play!
------------------------------------------
╬-YellzBellz Games!-╬ Cheesy
Offline Xyle
« Reply #4 - Posted 2009-07-08 05:20:45 »

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...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
<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!

Life is just a game, learn to play!
------------------------------------------
╬-YellzBellz Games!-╬ Cheesy
Offline zoto

Senior Devvie


Medals: 4



« Reply #5 - Posted 2009-07-08 05:37:08 »

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.
Offline Xyle
« Reply #6 - Posted 2009-07-09 02:14:23 »

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...

1  
2  
3  
4  
5  
6  
7  
8  
9  
      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.

Life is just a game, learn to play!
------------------------------------------
╬-YellzBellz Games!-╬ Cheesy
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (65 views)
2014-11-26 15:22:04

toopeicgaming1999 (58 views)
2014-11-26 15:20:36

toopeicgaming1999 (11 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (28 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (76 views)
2014-11-13 12:34:49

digdugdiggy (53 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!