Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

When I write in my terminal, java -jar myJar.jar, it gives me an error "Resource Not found res/playNow.png" When I run it in eclipse, it does not give me any errors about this image.

My folder in my eclipse is outside my package called res and inside it are images.

This is the full error

Exception in thread "main" java.lang.RuntimeException: Resource not found: res/playNow.png
    at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
    at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:169)
    at org.newdawn.slick.Image.<init>(Image.java:196)
    at org.newdawn.slick.Image.<init>(Image.java:170)
    at org.newdawn.slick.Image.<init>(Image.java:158)
    at org.newdawn.slick.Image.<init>(Image.java:136)
    at javagame.Menu.init(Menu.java:31)
    at javagame.Game.initStatesList(Game.java:21)
    at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:164)
    at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
    at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
    at javagame.Game.main(Game.java:32)

I'm using a terminal in my mac. How do I fix the error Resource Not Found? I'm using slick2d!

share|improve this question

1 Answer 1

Your resource folder has to be in the classpath. Just copy this folder in the folder holding the jar file and it should work. When you run your project in eclispe, the IDE already has settings that make it works. If you run the plain command java -jar myjar.jar java does not know where to look for your resources so it will look into the default classpath ("." e.g the current directory, that's why putting your resources on the same directory as your jar file would work). You can add parameters to the command line to change behaviors, change classpath etc. see the manual.

Also you can read this: http://docs.oracle.com/javase/tutorial/essential/environment/paths.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.