我正在尝试在andengine中加载tmx文件。我已经从AndEngine示例复制了示例并创建了一个我正在加载的新tmx文件。但是我在第tmxLoader.loadFromAsset(“tmx / test.tmx”)行上得到NullPointerException; 。 test.tmx文件只包含一个tile。它提供以下错误日志:
> 08-29 15:50:56.171: E/AndEngine(4495):
> TMXTiledMapExample.onCreateScene failed. @(Thread: 'GLThread 13')
> 08-29 15:50:56.171: E/AndEngine(4495): java.lang.NullPointerException
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.andengine.extension.tmx.TMXLayer.addTileByGlobalTileID(TMXLayer.java:274)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.andengine.extension.tmx.TMXLayer.initializeTMXTilesFromDataString(TMXLayer.java:247)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.andengine.extension.tmx.TMXParser.endElement(TMXParser.java:197)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.apache.harmony.xml.ExpatParser.endElement(ExpatParser.java:158)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.apache.harmony.xml.ExpatParser.appendBytes(Native Method) 08-29
> 15:50:56.171: E/AndEngine(4495): at
> org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:518)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318) 08-29
> 15:50:56.171: E/AndEngine(4495): at
> org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275) 08-29
> 15:50:56.171: E/AndEngine(4495): at
> org.andengine.extension.tmx.TMXLoader.load(TMXLoader.java:117) 08-29
> 15:50:56.171: E/AndEngine(4495): at
> org.andengine.extension.tmx.TMXLoader.loadFromAsset(TMXLoader.java:102)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> com.example.abc.TMXTiledMapExample.onCreateScene(TMXTiledMapExample.java:100)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.andengine.ui.activity.SimpleBaseGameActivity.onCreateScene(SimpleBaseGameActivity.java:48)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.andengine.ui.activity.BaseGameActivity$3.onCreateResourcesFinished(BaseGameActivity.java:169)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.andengine.ui.activity.SimpleBaseGameActivity.onCreateResources(SimpleBaseGameActivity.java:43)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:181)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:110)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
> 08-29 15:50:56.171: E/AndEngine(4495): at
> android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
即使我尝试加载示例提供的tmx文件,也会出现同样的错误。知道我哪里错了吗?
我正在使用Tiled Map Editor Vesion 0.8.1应用程序创建tmx文件。
答案 0 :(得分:1)
您是否获取了AndEngine的最新版本? 它接缝已修复:
https://github.com/nicolasgramlich/AndEngineTMXTiledMapExtension/pull/9
编辑:嗯,对不起,拉请求尚未提交。你应该尝试在你自己的git andengine repo中应用它。 或者作为简单的修复,您应该将tile ID更改为不同于0的值。