Dear all,
I’m creating a little multiplayer 2D game in Java using Tiled maps. I use libgdx on the client side, which loads and renders maps perfectly, but since I don’t want to use libgdx on the server side, I access maps via the libtiled v1.2.3 found on maven central.
Here is my test code:
MapReader mapReader = new MapReader();
Map tiledMap = null;
try {
tiledMap = mapReader.readMap("rooms/top.tmx");
} catch (IOException e) {
e.printStackTrace();
}
if (tiledMap == null) {
System.out.println("map is null");
return;
}
else {
System.out.println("map = " + tiledMap);
}
TileLayer ground = null;
for (MapLayer layer : tiledMap.getLayers()) {
if (layer.getName().equals("ground") && layer instanceof TileLayer) {
ground = (TileLayer) layer;
}
}
if (ground == null) {
System.out.println("ground is null");
return;
}
else {
System.out.println("ground = " + ground);
}
System.out.println("ground empty? " + ground.isEmpty());
Output:
map = Map[16x16x3][16x16]
ground = org.mapeditor.core.TileLayer@8297b3a
Exception in thread “main” java.lang.NullPointerException
at org.mapeditor.core.TileLayer.isEmpty(TileLayer.java:240)
The NPE occurs on the line with isEmpty()
Did I do something wrong?