Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jsoup's getelementbyid not working in asynctask

 
tasos georgiou
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.

 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:is JSoup supposed to be fully compatible with Android?


As far as i know it is.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • 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
  • 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
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic