I just started using Slick2D and learned how simple it is to load in a tilemap and display it. I tried atleast a dozen different tmx files from numerous examples to see if it was the actual file that was corrupted. Everytime I get this error:

Exception in thread "main" java.lang.RuntimeException: Resource not found: data/maps/desert.tmx
    at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
    at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:101)
    at game.Game.init(Game.java:17)
    at game.Tunneler.initStatesList(Tunneler.java:37)
    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 game.Tunneler.main(Tunneler.java:29)

Here is my Game class:

package game;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.tiled.TiledMap;

public class Game extends BasicGameState{
    private int stateID = -1;
    private TiledMap map = null;

    public Game(int stateID){
        this.stateID = stateID;
    public void init(GameContainer container, StateBasedGame game) throws SlickException{
        map = new TiledMap("data/maps/desert.tmx","maps");//ERROR
    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException{
    public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException{

    public int getID(){return stateID;}

I've tried to see if anyone else has had similar problems but haven't turned up anything. I am able to load other files, so I don't believe it's a compiler issue. My menu class can load images and display them just fine. Also, the filepath is correct.

Please let me know if you have any pointers that might help me sort this out.

  • 1
    \$\begingroup\$ I have used that very same constructor to load maps several times before. That, along with the error message of the exception, leads me to believe that it simply cannot find the file. Could you tell us where 1) the working directory that you are running the project from, 2) where the map file is. Please provide the paths as either fully qualified paths or relative to one parent folder common to both? \$\endgroup\$ – Jiddo Apr 29 '12 at 18:31
  • \$\begingroup\$ Yes, here's the path "F:\workspace\Game_Tunnel\data\maps\map.tmx". It's weird because in my menu class I load an image from "F:\workspace\Game_Tunnel\data\images\bg.jpg" \$\endgroup\$ – mbreen Apr 29 '12 at 18:36
  • \$\begingroup\$ That is just one of the paths. Where is your compiled source files? Where do you run the project from? (And how do you run your project? Eclipse? If so, what is the Eclipse project folder?) \$\endgroup\$ – Jiddo Apr 29 '12 at 18:38
  • \$\begingroup\$ I'm using eclipse and set my workspace to the foler "workspace" \$\endgroup\$ – mbreen Apr 29 '12 at 18:39
  • 1
    \$\begingroup\$ @Jiddo You should consolidate your comments into an answer so mbreen can accept it and you'll get the credit you deserve. \$\endgroup\$ – MichaelHouse May 1 '12 at 21:18

This answer is consolidated from my comments on the original question.

I have used that very same constructor to load maps several times before. That, along with the error message of the exception, leads me to believe that it simply cannot find the file.

Since your comments state that you can load other resources (images and sounds) but not this map that is an even stronger indication that this is the case. In Slick2D Images, Sounds, TiledMaps etc. are all loaded using this same method (the method ResourceLoader.getResourceAsStream).

Did you refresh your project in Eclipse after you created the map file? Can you see the map file from within Eclipse? Make sure you perform the refresh operation on the top of the hierarchy, on the project itself. (Right-click on the project and use refresh.) If that doesn't work, try re-creating the project. (I've never needed to do that tho.)


I have had a similar problem. but have figured out how to make sure it will load. first thing you would do is create the TiledMap object like so

public TiledMap map = null;

now you just need to tell it not to load the tilesets unless you want it to but in my game i have loaded the tilesets differently

public void load(){
     map = new TiledMap("filepath", false);

Right click on the java app that is giving you the error message. Go to >RUN CONFIGURATION. Take a look at the MAIN CLASS line. The MAIN CLASS should be the class that has your main class method in it. If it doesn't, look at the left panel and find the main class that is calling your java app. Click on it and make sure that it is set as the main class in the MAIN CLASS line.

  • \$\begingroup\$ I'm not sure you're answering the correct question. Changing the main class for a java application cannot be done from the running java app. Additionally, this doesn't say anything about loading tmx files. The error being presented has nothing to do with setting the main class. \$\endgroup\$ – MichaelHouse Feb 2 '13 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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