• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jsoup's getelementbyid not working in asynctask

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using getElementById method of jsoup to get the content of id "content-main".When i'm running it as a java application everything works as it should, but as an android app not.I just get null.I'm using the following code inside doInBackground of AsyncTask.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is JSoup supposed to be fully compatible with Android?
 
tasos georgiou
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:is JSoup supposed to be fully compatible with Android?



As far as i know it is.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does 'not working mean? What is the error/problem?

Are you using System.out.println(t) in the Android version? Does the app have a console to print to? Are you looking at the correct console? What happens if you send output to Log.d("Parse HTML", t) instead (using LogCat or similar to look at the logs)?

What is the user agent used when sending the request? Does the receiver know it is coming from Android/mobile device? Does it have a mobile view? Does that mobile view have the element ID you are looking for?

These are the questions I would be asking if this where my problem...
 
tasos georgiou
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Luke wrote:What does 'not working mean? What is the error/problem?

Are you using System.out.println(t) in the Android version? Does the app have a console to print to? Are you looking at the correct console? What happens if you send output to Log.d("Parse HTML", t) instead (using LogCat or similar to look at the logs)?

What is the user agent used when sending the request? Does the receiver know it is coming from Android/mobile device? Does it have a mobile view? Does that mobile view have the element ID you are looking for?

These are the questions I would be asking if this where my problem...



I get NullPointerException also when i use Log.d("Parse HTML", t.getElementById("content-main").text()).The emementID (content-main) exists, besides as i said it works as it is supposed when i'm running the same code as a java application.I don't get there a NullPointerException
Also i forgot to mention that i use System.out.println and Log.d() on postExecute of an AsyncTask.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you made sure that the page you're getting *on the device* actually contains an ID called "content-main", as Steve suggested? Just because the page you're getting in a desktop app contains that element does not mean the page you're getting on the device contains it, too.
 
tasos georgiou
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Have you made sure that the page you're getting *on the device* actually contains an ID called "content-main", as Steve suggested? Just because the page you're getting in a desktop app contains that element does not mean the page you're getting on the device contains it, too.



Did't thought about that.That could be the problem since the problem appears with that ID, while with others there is no problem.I'll check it and see what happens.Thank's both of you.
 
tasos georgiou
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was it.I was getting the mobile version of the page where the specific elementID didn' exist.Thanks again.
 
reply
    Bookmark Topic Watch Topic
  • New Topic