[SOLVED]Having same error as everyone else: ResourceLoader cannot find image

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

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”

  • 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");

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.