1

私は Appcelerator Titanium を使用しています。以下のコードは iPhone では正常に動作しますが、Android では動作せず、その理由がわかりません。誰でも助けることができますか?

次のエラーで失敗します。

TypeError: プロパティ "DocumentElement" を null から読み取れません

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
4

1 に答える 1

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
于 2011-03-21T00:35:49.290 に答える