Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  lwjgl, jarsplice, distributing problem  (Read 352 times)
0 Members and 1 Guest are viewing this topic.
Offline PaidGEEK

JGO n00b
*

Posts: 17
Medals: 1



« on: 2012-01-23 18:27:55 »

Im sure this has been answered before, but I will ask it anyway. I exported my lwjgl game and used jarsplice to create fat jar, simple.
But when runnng my game I get image not loaded exception. Basically textures failed to load. Do I have to make some sort of workaround for this to work? I use slick Textureloader and imageIO for a couple of images which works perfectly when debugging from eclipse. It seems I get exception under imageIO.

How can I get it to work?


Improvisational programmer.
Offline kappa
« League of Dukes »

JGO Kernel
*****

Posts: 2360
Medals: 59


★★★★★


« Reply #1 on: 2012-01-23 18:39:45 »

can you paste the full exception?

If I was to guess, I'd say you are using File to load the image when you should be using an InputStream for images that are in a jar, but will need to see exception to confirm.
Offline PaidGEEK

JGO n00b
*

Posts: 17
Medals: 1



« Reply #2 on: 2012-01-23 18:52:42 »

Well I load this single image as bufferedImage, and catch exception which i can see later when running:

1  
2  
3  
4  
5  
6  
7  
8  
9  
public static void load(){
      imageMain = null;
      try {
         imageMain = ImageIO.read(new File("res/fonts/font.png"));   //loads main fonts image
     } catch (IOException e) {
         System.out.println("cant load fonts Image!");
         System.exit(0);
      }
   }

I use this one later to get subimages...


And then I load a bunch more textures using InputStream for "regular use":

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
public static Texture basic;
   public static Texture orange;
   public static Texture blue;
   //public static Texture text;
  public static Texture menuBG;
   public static Texture stars;
   public static Texture moon;
   public static Texture redPlanet;
   public static void initTexs(){
      try {
         basic = TextureLoader.getTexture("PNG",new FileInputStream(new File("res/tex/basic.png")));
         orange = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/tex/orange.png")));
         blue = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/tex/blue.png")));
         stars = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/tex/stars.png")));
         menuBG = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/menu/background.png")));
         moon = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/tex/moon.png")));
         redPlanet = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/tex/redplanet.png")));
         System.out.println("Textures are loaded!");
      } catch (IOException e) {
         e.printStackTrace();
         System.out.println("Error while loading textures!");
         Display.destroy();
         System.exit(0);
      }
   }

Improvisational programmer.
Games published by our own members! Go get 'em!
Offline kappa
« League of Dukes »

JGO Kernel
*****

Posts: 2360
Medals: 59


★★★★★


« Reply #3 on: 2012-01-23 19:28:51 »

Well there is your problem Smiley, you can't use File when reading images from a jar file, you need to use an InputStream. File only works when reading files from a file system (as you are when running from eclipse).

Since you are using Slick you should use its useful ResourceLoader class to do this automatically for you (so doesn't matter if you are loading a file from a filesystem or a jar).

See the slick image loading tutorial here.

So with your code you wouldn't use :
1  
basic = TextureLoader.getTexture("PNG",new FileInputStream(new File("res/tex/basic.png")));

but instead use
1  
basic = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/tex/basic.png"));


As for your ImageIO.read line you can still use ResourceLoader as follows:
1  
imageMain = ImageIO.read(ResourceLoader.getResourceAsStream("res/fonts/font.png"));   //loads main fonts image


hope that helps.
Offline PaidGEEK

JGO n00b
*

Posts: 17
Medals: 1



« Reply #4 on: 2012-01-23 19:58:21 »

Yep! It works now! Thank you for your help Smiley

Improvisational programmer.
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.123 seconds with 20 queries.