Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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]Having same error as everyone else: ResourceLoader cannot find image  (Read 201 times)
0 Members and 1 Guest are viewing this topic.
Offline Nausica
« Posted 2014-05-14 06:15:40 »

I've read over so many threads on this issue, and I've literally tried everything. It simply will not work outside of Eclipse. Within Eclipse, every suggestion or proposed solution works fine, but when packing it as a fat jar it will always throw a NPE(If I'm using ClassLoader() or class .getResourceAsStream()) or a Runtime Exception: Resource not found (If I'm using the slick ResourceLoader).

For simplicity, I'll just refer to one spritesheet loading call here:

1  
Spritesheet.createSpriteSheet(8d, 8d, "arkanoid.png", ARK);


the load method:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
private void loadSpriteSheet(String path){
      try{
         texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(path));
         texture.setTextureFilter(GL_NEAREST);
         imageWidth = texture.getImageWidth();
         imageHeight = texture.getImageHeight();
         if (spriteWidth == 0) {
            spriteWidth = imageWidth;
         }
         if (spriteHeight == 0) {
            spriteHeight = imageHeight;
         }
      } catch(FileNotFoundException e){
         
      } catch (IOException e) {
         e.printStackTrace();
      }
   }


a quick screencap of the file hierarchy in Eclipse:



and a screencap of the hierarchy of the JAR file opened in WinRAR:




and the error through cmd:



And like I said, I've tried everything from ClassLoader() to getClass().getClassLoader(), and even trying Main.class.getResourceAsStream, and I've tried adding a res folder to the source, having the res folder within the package, etc. and I can always get it to work within Eclipse, but never when exported. This current build is one such case.
Offline Nausica
« Reply #1 - Posted 2014-05-14 06:26:52 »

screencap of new file hierarchy



starting to get really annoyed at these subtle differences

If you are having this problem, note that nothing has worked for me other than the above. Take note that "res" is not a source folder, just a simple folder created by Right Click package name -> New folder. Many threads and also questions on SO say to create a new Source Folder, say to add the folder to the Build Path. None of that worked, just add a new regular folder and reference images by "package/subfoldername/resourcename.extension"
Offline trollwarrior1
« Reply #2 - Posted 2014-05-14 06:34:29 »

- Create a 'res' folder in your main project directory (1)
- Right click on your project -> Properties -> Java Build Path -> Libraries -> Add Class Folder (2)
- Select you 'res' folder (3)
- Hit OK on all the windows open

Now you can access the resources FROM your res folder. If you have a resources in your res folder in path '/res/images/image.png', the way you access it is by doing Class.class.getResource("/images/image.png");

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nausica
« Reply #3 - Posted 2014-05-14 06:38:51 »

trollwarrior1, just tried that method. Did not work. Throws the same exception as in the OP. Just like before, it works fine in Eclipse, like I expected since it's no different than reference a source folder. However as soon as I create a fat jar, it throws an error.
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.

Mr.CodeIt (20 views)
2014-12-23 03:34:11

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

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

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

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

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

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

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

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

toopeicgaming1999 (148 views)
2014-11-26 15:20:36
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!