mbreen
mbreen

Reputation: 558

java slick cannot load tmx tilemaps

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{
        //map.render(0,0);
    }
    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.

Upvotes: 0

Views: 1632

Answers (1)

jefflunt
jefflunt

Reputation: 33954

This looks like a "file not found" problem. It's basically saying that it can't find the file (read: "resource") that you specified. Check your relative path, data/maps/desert.tmx and make sure it's right.

If that doesn't work, replace your relative path with an absolute path (from the root of your file system), just for testing, and see if that works. If that does work, then your relative path should work, but it's just not specified correctly. One of the most common problems I see is not going up a couple of folders when looking for resources. For example, maybe the correct relative path for you is ../../data/maps/desert.tmx, or something along those lines. You need to determine, for sure, in what folder your code is being executed from (maybe a bin folder?), and specify the relative path from there.

Upvotes: 1

Related Questions