java.lang.NullPointerException
at org.newdawn.slick.tiled.TileSet.<init>(TileSet.java:139)
at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:661)
at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:106)
at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:90)
at game.Game.init(Game.java:20)
at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
at game.Main.main(Main.java:26)
Mon Mar 23 14:56:44 EDT 2015 ERROR:Failed to parse tilemap
org.newdawn.slick.SlickException: Failed to parse tilemap
at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:695)
at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:106)
at org.newdawn.slick.tiled.TiledMap.<init>(TiledMap.java:90)
at game.Game.init(Game.java:20)
at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:171)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317)
at game.Main.main(Main.java:26)
Caused by: java.lang.NullPointerException
at org.newdawn.slick.tiled.TileSet.<init>(TileSet.java:139)
at org.newdawn.slick.tiled.TiledMap.load(TiledMap.java:661)
... 7 more
does anyone know why ive been getting this error
im just trying to render my tilemap in a basic statebasedgame
That looks like a bug in Slick2D. Here’s the snippet of code it’s choking on:
for (int i = 0; i < pElements.getLength(); i++) {
Element tileElement = (Element) pElements.item(i);
int id = Integer.parseInt(tileElement.getAttribute("id"));
id += firstGID;
Properties tileProps = new Properties();
Element propsElement = (Element) tileElement.getElementsByTagName(
"properties").item(0);
NodeList properties = propsElement.getElementsByTagName("property"); // line 139
for (int p = 0; p < properties.getLength(); p++) {
Element propElement = (Element) properties.item(p);
String name = propElement.getAttribute("name");
String value = propElement.getAttribute("value");
tileProps.setProperty(name, value);
}
props.put(new Integer(id), tileProps);
}
Here, it’s going through all the <tile> elements in a <tileset>, and the error it makes is that it assumes that a <tile> element always has a child <properties> element. There isn’t one, so it runs into a null pointer exception.
This has always been a wrong assumption, though until recently it will have mostly worked fine. Now, Tiled has other reasons to write out a <tile> element than it having properties (like maybe it has terrain information or maybe it has its own image reference).
So, apart from the bug, Slick2D also does not yet support for example image collection tilesets added with Tiled 0.10. You’ll want to talk to the Slick2D developers about fixing it and possibly adding support for newer Tiled features.
I do appreciate the help. To clarify, your saying tiled doesn’t really work with slick2d anymore ,or did I create the map incorrectly? I heard slick2d stopped development but it is open source correct me if im wrong because im unsure. How would i go about fixing the problem. I’d have to give my tiles properties?
Right, if you’re familiar with Java it should be trivial for you to fix this bug in Slick2D and keep going. However, depending on what feature you’re using you will either have to add it to Slick2D or stop relying on it.
My guess is that you’ve created an “image collection” tileset in Tiled, and unless you modify Slick2D to support this it will not be able to render your map correctly.