Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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 1152 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:

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

the load method:

private void loadSpriteSheet(String path){
         texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(path));
         imageWidth = texture.getImageWidth();
         imageHeight = texture.getImageHeight();
         if (spriteWidth == 0) {
            spriteWidth = imageWidth;
         if (spriteHeight == 0) {
            spriteHeight = imageHeight;
      } catch(FileNotFoundException e){
      } catch (IOException e) {

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  

DesertCoockie (20 views)
2018-05-13 18:23:11

nelsongames (68 views)
2018-04-24 18:15:36

nelsongames (65 views)
2018-04-24 18:14:32

ivj94 (748 views)
2018-03-24 14:47:39

ivj94 (79 views)
2018-03-24 14:46:31

ivj94 (595 views)
2018-03-24 14:43:53

Solater (95 views)
2018-03-17 05:04:08

nelsongames (168 views)
2018-03-05 17:56:34

Gornova (378 views)
2018-03-02 22:15:33

buddyBro (1038 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!