Appcelerator 问答链接: Android 上的 XML 解析失败,但在 iPhone 上有效
我正在准备一个通用应用程序,它适用于 iPhone 和 Android 手机,其代码与 Titanium 主要用于相同的代码。使用相同的代码,我发现 XML 文档解析的结果不同,并且我的 android 应用程序无法正确加载它。它会导致 NULLPointer 异常。但同样的代码在 iPhone 上也能完美运行。
你能检查一下吗?
xyz(languageCode, currentVersion, xmldoc) {
try {
Ti.API.info('Start parsing the library');
var archiveData = xmldoc.getElementsByTagName('archive');
Ti.API.info('Archive: ' + archiveData);
Ti.API.info('Item: ' + archiveData.item);
Ti.API.info('Lendth: ' + archiveData.length);
var newVersion = archiveData.item(0).getAttribute('version');
}catch(e){
Ti.API.info('Library Went In Catch: ' + e);
}
函数调用:来自 Ti.Network.HttpClient 的 onload() 方法
xyz(语言代码,版本,this.responseXML.documentElement);
iPhone的输出:
存档:[对象 TiDOMNodeList]
[INFO] 项目:[对象 TiDOMNodeList]
[信息] 长度:1
安卓的输出:
[信息] [3,7225] 存档:[Ti.NodeList]
[信息] [1,7226] 项目:[KrollMethod 项目]
[信息] [2,7228] 长度:0 [信息]
[235,7466] 库进入 Catch:JavaException:java.lang.NullPointerException:null