问题
I keep getting null pointer exceptions when I try and use TextureAtlass with this libgdx project. game.atlas and game.png are under android/assets
game.png
size: 1024,1024
format: RGBA8888
filter: Nearest,Nearest
repeat: none
bunny_head
rotate: false
xy: 2, 44
size: 122, 82
orig: 122, 82
offset: 0, 0
index: -1
Load the atlas with
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("game.atlas"));
head = atlas.findRegion("bunny_head");
This is my Exception log
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.fancylancy.game.WorldController.initTestObjects(WorldController.java:49)
at com.fancylancy.game.WorldController.init(WorldController.java:39)
at com.fancylancy.game.WorldController.<init>(WorldController.java:33)
at com.fancylancy.game.Game.create(Game.java:20)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:143)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
回答1:
How are you running your project? If it's from within an IDE on the desktop, have you remembered to set the current working directory to be android/assets?
If not, then it won't find game.atlas which could cause the issue you see.
Appologies for posting this as an answer btw - I don't have enough reputation to post it as a comment.
来源:https://stackoverflow.com/questions/30046163/textureatlas-issue-with-libgdx