2011-03-20 95 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

相关问题