机器人:如何加载的资产目录中的XML文件? [英] android: how to load xml file from assets directory?

查看:782
本文介绍了机器人:如何加载的资产目录中的XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦装载从资产目录中的XML文件。 使用同一条线路的code(只是改变了路径)我得到不同的结果(OK或NPE /文件损坏) 文件castle1.tmx(这是一个XML文件)将被复制在两个位置:

  • RES / XML / castle1.tmx
  • 在资产/级别/ castle1.tmx

这条线,它的工作原理:

  XmlResourceParser XRP = ctx.getAssets()openXmlResourceParser(RES / XML / castle1.tmx)。
 

在与这条线是没有:

  XmlResourceParser XRP = ctx.getAssets()openXmlResourceParser(资产/级别/ castle1.tmx)。
 

我得到以下结果:

  04-05 21:46:40.940:WARN /的ResourceType(29056):坏XML块:头大小28024或总大小1702240364比数据大小70441大
04-05 21:46:40.940:ERROR / TestParser(29056):无法读取资源文件
04-05 21:46:40.940:WARN / System.err的(29056):java.io.FileNotFoundException:损坏的XML二进制文件
04-05 21:46:40.940:WARN / System.err的(29056):在android.content.res.AssetManager.openXmlAssetNative(本机方法)
04-05 21:46:40.944:WARN / System.err的(29056):在android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:485)
04-05 21:46:40.944:WARN / System.err的(29056):在android.content.res.AssetManager.openXmlResourceParser(AssetManager.java:453)
04-05 21:46:40.944:WARN / System.err的(29056):在android.content.res.AssetManager.openXmlResourceParser(AssetManager.java:442)
04-05 21:46:40.944:WARN / System.err的(29056):在game.test.MapLoader< INIT>(MapLoader.java:73)。
 

文件在这两个案例中发现... 这只是我似乎无法能够使用该方法从资产目录读取它。

任何想法如何从资产目录加载我的xml文件?

TNX

解决方案

RES / 文件夹中的所有XML文件是precompiled,而在资产/ 文件夹,它们不是。所以,你不能使用 openXmlResourceParser()与非precompiled资源。相反,使用的open()并通过的InputStream 读取文件。<​​/ P>

i have trouble loading an xml file from assets directory. using the same line of code (just changing the path) i get different results ( either ok or NPE / file corrupted ) the file "castle1.tmx" (it's an xml file) is copied in two locations:

  • res/xml/castle1.tmx
  • assets/level/castle1.tmx

with this line, it works:

XmlResourceParser xrp = ctx.getAssets().openXmlResourceParser("res/xml/castle1.tmx");

while with this line it doesn't:

XmlResourceParser xrp = ctx.getAssets().openXmlResourceParser("assets/level/castle1.tmx");

i get the following result:

04-05 21:46:40.940: WARN/ResourceType(29056): Bad XML block: header size 28024 or total size 1702240364 is larger than data size 70441
04-05 21:46:40.940: ERROR/TestParser(29056): Unable to read resource file
04-05 21:46:40.940: WARN/System.err(29056): java.io.FileNotFoundException: Corrupt XML binary file
04-05 21:46:40.940: WARN/System.err(29056):     at android.content.res.AssetManager.openXmlAssetNative(Native Method)
04-05 21:46:40.944: WARN/System.err(29056):     at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:485)
04-05 21:46:40.944: WARN/System.err(29056):     at android.content.res.AssetManager.openXmlResourceParser(AssetManager.java:453)
04-05 21:46:40.944: WARN/System.err(29056):     at android.content.res.AssetManager.openXmlResourceParser(AssetManager.java:442)
04-05 21:46:40.944: WARN/System.err(29056):     at game.test.MapLoader.<init>(MapLoader.java:73)

file is found in both case... it's just that i cannot seem to be able to read it from asset dir using that method..

any ideas how can i load my xml file from assets directory ?

tnx

解决方案

In res/ folder all xml files are precompiled, whereas in assets/ folder they are not. So, you can't use openXmlResourceParser() with non-precompiled resources. Instead use open() and read file through InputStream.

这篇关于机器人:如何加载的资产目录中的XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆