我正在尝试在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文件。
您获取了AndEngine的最后一个版本吗。它已经修复了:
https://github.com/nicolasgramlich/AndEngineTMXTiledMapExtension/pull/9
编辑:哼,对不起,拉取请求还没有提交。您应该尝试在自己的git和engine repo中应用它。或者,作为一个简单的解决方案,您应该将tile Id更改为不同于0的值。