While following a tutorial with LibGDX, I am working with tile maps.
This is the method that I’m using:
tilemap.getLayers().get("Collision Layer");
or
tilemap.getLayers().get(1); //1 is the second layer, the collision layer
The problem is, is that when I try to get a certain layer from the tile map, it return a null pointer error like so:
Exception in thread “LWJGL Application” java.lang.NullPointerException at com.mytut.game.Player.Init(Player.java:25)
at com.mytut.game.MyTutGame.create(MyTutGame.java:70)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
I have tried various ways of getting the layer but none of them seem to work.
Here’s an image of my tile map in the Tiled map editor: