0

我正在尝试在andengine 中加载一个tmx 文件。我已经从 AndEngine 示例中复制了示例并创建了一个新的 tmx 文件,我正在加载该文件。但是我在 tmxLoader.loadFromAsset("tmx/test.tmx"); 线上得到了 NullPointerException . test.tmx 文件只包含一个图块。它给出以下错误日志:

> 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 文件。

4

1 回答 1

1

您是否获取了最新版本的 AndEngine。它似乎已被修复:

https://github.com/nicolasgramlich/AndEngineTMXTiledMapExtension/pull/9

编辑:嗯,抱歉,拉取请求尚未提交。您应该尝试将它应用到您自己的 git 和引擎存储库中。或者作为一个简单的修复,您应该将您的图块 ID 更改为不同于 0 的值。

于 2012-08-29T11:38:38.907 回答