Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

cannot read propert documentElement from null, only Android?

I facing a problem in reading rss feeds from a website, it works good on Iphone and it was working on Android but suddenly I got this error message

TypeError: Cannot read property "documenyElemnt" from null

I've tried this solution :
delete the contents of the immediate subdirectories of /build/android,Then click the Save Changes button to force a full rebuild and launch the app

but it doesn't work

this is my code:

var xhr = Ti.Network.createHTTPClient();
var url = 'MyUrl';


xhr.open("GET", url);
xhr.onload = function(){
        var doc = this.responseXML.documentElement;
        var items = doc.getElementsByTagName("item");

It was working for couples of weeks , and I didn't change my code !

— asked October 17th 2011 by Haya aziz
  • android
  • build
  • error
  • httpclient
  • xml
0 Comments

3 Answers

  • "responseXML" is "null". I don't know why (maybe some error occurred in fetching remote data), but that's a good point where to start searching for the error. :)

    — answered October 17th 2011 by Ivan Škugor
    permalink
    8 Comments
    • Waiting for your searching result :)

      — commented October 17th 2011 by Haya aziz
    • No, no … you're the one who need to search, I can't debug your code. :D

      I've pointed where to start, now you need to do job. ;)

      — commented October 17th 2011 by Ivan Škugor
    • I didn't write my question until I faced a closed door and can not get any solution , I didn't write it to guide me from where to search, thanks anyway

      — commented October 17th 2011 by Haya aziz
    • I told you: "responseXML" is "null".

      So, most probably you didn't get any response. Why is that so is hard to tell - maybe you don't have internet connection, server returned error, etc.

      Did you try to add "onerror" function? What status is returned?
      Check in documentation how to do that: https://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Network.HTTPClient-object

      — commented October 17th 2011 by Ivan Škugor
    • I'm getting confused because the same code and the same url works very good on Iphone, I've tried xhr.onerror but it didn't fire,this.status returns 200, this.responseText returns null ??

      — commented October 18th 2011 by Haya aziz
    • Are you sure that XML you got from server is valid? Maybe there is some XML parse error and iOS has some error handling system while Android has not (although, when I think a bit about that, XML is valid or it is not valid, there is no between).

      If that is not the case, I think you should make good example that reproduces your error and report it to the JIRA CE.

      — commented October 18th 2011 by Ivan Škugor
    • thank you for your corporation, now I have two URLs with the same situation, works good on Iphone but not on Android, I'll try my best to find a solution

      — commented October 18th 2011 by Haya aziz
    • one more helpful info that this.responseData returns all the information as an object but I want it as xml ?

      — commented October 22nd 2011 by Haya aziz
  • thank you for your corporation, now I have two URLs with the same situation, works good on Iphone but not on Android, I'll try my best to find a solution

    — answered October 18th 2011 by Haya aziz
    permalink
    1 Comment
    • ^ by mistake , sorry

      — commented October 18th 2011 by Haya aziz
  • solved by this code

    if (this.responseXML == null) 
              var doc = Ti.XML.parseString(this.responseData.toString());
             else 
             var doc = this.responseXML.documentElement;
    
    — answered October 22nd 2011 by Haya aziz
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.