我正在使用Appcelerator Titanium,下面的代碼在iPhone上正常工作,但在Android上沒有,我無法找出原因。誰能幫忙?爲什麼此Appcelerator代碼在iPhone上工作,但不在Android上?
它失敗,出現以下錯誤:
類型錯誤:無法從空讀取屬性「DocumentElement」
BEGIN CODE
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function() {
var xmlDoc = Ti.XML.parseString(this.responseText).documentElement;
var xlinestatus = xmlDoc.getElementsByTagName('LineStatus');
for (i = 0; i < xlinestatus.length; i++) {
var theItem = xlinestatus.item(i);
var newname = theItem.getElementsByTagName("Line").item(0).getAttribute("Name");
var desc = theItem.getElementsByTagName("Status").item(0).getAttribute("Description");
var active = theItem.getElementsByTagName("Status").item(0).getAttribute("IsActive");
Ti.API.info(" Line: " + newname + " Status: " + desc + ", Active: " + active);
}
};
// open the client
xhr.open('GET', 'http://cloud.tfl.gov.uk/TrackerNet/LineStatus');
// send the data
xhr.send({});
END CODE
你將不得不提供更多信息什麼是logcat輸出? 是否有一個例外是什麼this.responseText的價值? – sherif 2011-03-20 21:59:36
我有類似的問題,請檢查問題:http://stackoverflow.com/questions/8163385/xml-parsing-failure-on-android-but-works-on-iphone – 2011-11-17 07:25:18
http://developer.appcelerator.com/question/128341/xml-parsing-failure-on-android-but-works-on-iphone – 2011-11-17 07:26:08