2011-03-20 92 views
1

我正在使用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 
+0

你將不得不提供更多信息什麼是logcat輸出? 是否有一個例外是什麼this.responseText的價值? – sherif 2011-03-20 21:59:36

+0

我有類似的問題,請檢查問題:http://stackoverflow.com/questions/8163385/xml-parsing-failure-on-android-but-works-on-iphone – 2011-11-17 07:25:18

+0

http://developer.appcelerator.com/question/128341/xml-parsing-failure-on-android-but-works-on-iphone – 2011-11-17 07:26:08

回答

0

這是我做過什麼和它的工作

請更改線路Ti.XML.parseString(this.responseText).documentElement;

this.responseXML.documentElement它應該工作。這是它的輸出。我沒有在OS X上測試過,但它應該可以工作。

[INFO] [157,5791] Line: Bakerloo Status: Service Closed, Active: true 
[INFO] [8,5799] Line: Central Status: Service Closed, Active: true 
[INFO] [27,5826] Line: Circle Status: Service Closed, Active: true 
[INFO] [7,5833] Line: District Status: Service Closed, Active: true 
[INFO] [16,5849] Line: Hammersmith and City Status: Service Closed, Active: true 
[INFO] [11,5860] Line: Jubilee Status: Service Closed, Active: true 
[INFO] [12,5872] Line: Metropolitan Status: Service Closed, Active: true 
[INFO] [12,5884] Line: Northern Status: Service Closed, Active: true 
[INFO] [14,5898] Line: Piccadilly Status: Service Closed, Active: true 
[INFO] [14,5912] Line: Victoria Status: Service Closed, Active: true 
[INFO] [14,5926] Line: Waterloo and City Status: Service Closed, Active: true 
+0

我並不熟悉在這種情況下的錯誤處理,但是你的意思是引用'inError'嗎?或者它是一個變量?如果不是,我不確定這會揭示什麼? – Basic 2011-03-21 00:37:56

+0

檢查上面的答案應該工作。將不得不找到你的電話爲什麼在iPhone上工作,並在android – allthenutsandbolts 2011-03-21 01:26:56

+0

上失敗我編輯了你的答案,正確指出代碼片段。對於未來的帖子,請注意,您可以使用反引號(')或縮進來實現此目的。感謝您在SO上的努力並歡迎:) – Basic 2011-03-21 02:34:34

相關問題