Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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  
  [SOLVED] Runnable JAR outputs (input == null) IOException error after exporting.  (Read 441 times)
0 Members and 1 Guest are viewing this topic.
Offline tom_mai78101
« Posted 2014-03-17 03:48:47 »

For those who wanted to help out, here's a link to my GitHub repository, so that anyone can help look at the problem.
GitHub repository: http://github.com/tommai78101/PokemonWalking.git

I'm having trouble with exporting a runnable JAR file recently. The problem seems to be an issue with class paths, but I've checked to see there's no issues with it.
I'm actually stumped by this problem. I'm going to post a few pictures in hope that someone else may point out the problem that I didn't see.

Picture of class path settings:



Picture of the output error log via console:



Loading resources code:
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  
26  
27  
28  
public class Art {
   
   //Entities
   public static BaseBitmap[][] player;
   public static BaseBitmap[][] testDownAnimation;
   
   //Tiles
   public static BaseBitmap testTile;
   public static BaseBitmap smallTree;
   
   //Area
   public static BaseBitmap testArea;
   public static BaseBitmap testArea2;
   
   //Others
   public static BaseBitmap sprite;
   
   public static void loadAllResources(BaseScreen screen) {
      sprite = screen.load("/art/test.png");
      player = screen.cut("/art/player/player.png", 16, 16, 0, 0);
      testTile = screen.load("/art/floor/testTile.png");
      smallTree = screen.load("/art/wall/treeSmall.png");
      testDownAnimation = screen.cut("/art/player/test_walk_down_animation.png", 16, 16, 0, 0);
     
      testArea = screen.load("/area/test/testArea.png");
      testArea2 = screen.load("/area/test/testArea2.png");
   }
}


Any answers/suggestions are fully welcomed.  Sad
Offline jonjava
« Reply #1 - Posted 2014-03-17 05:51:57 »

Try adding the res folder in the "Source" tab not the "Library" tab. Also what does your "screen.load()" method look like?

Offline tom_mai78101
« Reply #2 - Posted 2014-03-17 09:15:13 »

The screen.load() method is actually based on a superclass. It consists of the entire thing, so here you go:

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  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
package screen;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

public class BaseBitmap {
   protected int[] pixels;
   protected int width;
   protected int height;
   
   public BaseBitmap(int w, int h) {
      this.width = w;
      this.height = h;
      this.pixels = new int[w * h];
   }
   
   public BaseBitmap(int w, int h, int[] p) {
      this.width = w;
      this.height = h;
      this.pixels = p;
   }
   
   public BaseBitmap load(String filename) {
      try {
         BufferedImage image = ImageIO.read(BaseBitmap.class.getResource(filename));
         return load(image);
      }
      catch (IOException e) {
         e.printStackTrace();
      }
      return null;
   }
   
   public BaseBitmap load(BufferedImage image) {
      if (image == null) return null;
     
      int width = image.getWidth();
      int height = image.getHeight();
     
      return new BaseBitmap(width, height, image.getRGB(0, 0, width, height, null, 0, width));
   }
   
   public BaseBitmap[][] cut(String filename, int w, int h, int clipW, int clipH) {
      try {
         BufferedImage image = ImageIO.read(BaseBitmap.class.getResource(filename));
         int xTiles = (image.getWidth() - clipW) / w;
         int yTiles = (image.getHeight() - clipH) / h;
         BaseBitmap[][] results = new BaseBitmap[xTiles][yTiles];
         for (int x = 0; x < xTiles; x++) {
            for (int y = 0; y < yTiles; y++) {
               results[x][y] = new BaseBitmap(w, h);
               image.getRGB(clipW + x * w, clipH + y * h, w, h, results[x][y].pixels, 0, w);
            }
         }
         return results;
      }
      catch (IOException e) {
         e.printStackTrace();
      }
      return null;
   }
   
   public int getWidth() {
      return this.width;
   }
   
   public int getHeight() {
      return this.height;
   }
   
   public int[] getPixels() {
      return this.pixels;
   }
}


And I just checked to see if moving the class path to the "Source" tab helps. Same error occurred.

Class Path right now:

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jonjava
« Reply #3 - Posted 2014-03-17 09:47:16 »

Try using the classLoaders getResource() method or removing the first '/' from the path name.

http://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String)
http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResource(java.lang.String)

http://stackoverflow.com/questions/6608795/what-is-the-difference-between-class-getresource-and-classloader-getresource

Offline tom_mai78101
« Reply #4 - Posted 2014-03-17 13:16:56 »

First of all, I reverted back by moving the "res" folder from the "Source" tab to the "Libraries" tab.

Then I tried using the ClassLoader method. When debugging, an error occurred saying the ImageIO.read() caught an unknown source URL.

Then I removed the '/' in front of each of the file paths. Debugging the application works correctly, but it doesn't work when I finished exporting it as a Runnable Jar.

Here is the error log via command prompt:



I also did a test to see if it's a problem with Eclipse by creating a new Java project, using the load() method below, and then exporting it as a runnable JAR:

1  
2  
BufferedImage image = ImageIO.read(BaseBitmap.class.getResource("/test/this/folder/out.png");
//Yes, it is 3 folders deep.


The result show that the JAR executable runs correctly, with no error logs or whatever, and the out.png image is displayed properly on the screen. This led me to suspect that there's something wrong with the setup that's persistent in the GitHub repository.

Another thing I recreated that's shown below (I reused and modified the screenshot as a test image.) Turns out that the exported runnable JAR outputted an error message in the command prompt stating: "no main manifest attribute in test.jar". I now have no more clues to continue on.

Offline jonjava
« Reply #5 - Posted 2014-03-17 13:39:53 »

Do you want the res folder to be packed inside the jar file itself?

[EDIT]: And also, re-read the links I posted about relative paths and how the getResource() method works and differns from class and ClassLoader.

Offline tom_mai78101
« Reply #6 - Posted 2014-03-17 14:14:53 »

Okay, I re-read the links. I think I have figured it out.

I put this code just before I used ImageIO.read() to get the resource URLs.

1  
2  
3  
4  
5  
         Enumeration<URL> urls = this.getClass().getClassLoader().getResources(filename);
         for (URL url = null; urls.hasMoreElements();) {
            url = urls.nextElement();
            System.out.println(url.toString());
         }


What it does is, it outputs only 4 image URLs, when it should have been 5 image URLs. I went and check the file path in the source codes first, then commented out any references to the fifth image URL. Finally, I did an export of my project.

The result is a success.  Grin

Now, I was curious as to why it's not working before, so I went and check the resource file. Lo and behold, the resource file had a file extension name in all capital letters. (It should be ".png", but it was ".PNG".) The moment I saw it, I realized what it was: corrupted file.

I went ahead and fix the corrupted file by reloading/resaving/overwriting over the file with a fresh copy. Then uncomment the references I had in my source code. Debugged to check to see if everything is okay. Finally, re-export the project as a runnable JAR.

The result is now a success.  Grin



You can actually tell what I did. Problem solved.  Pointing
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

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

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

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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