0
\$\begingroup\$

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:

Map

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

After looking through my code over and over again, I found what I did wrong:

The problem was that I hadn't initialized my tile map before I was trying to get the layers of the tile map, so it gave me the exception.

All I needed to do was move the tile map initialization before I found the layers.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .