This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Android and the fly likes Jsoup's getelementbyid not working in asynctask Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Mobile » Android
Bookmark "Jsoup Watch "Jsoup New topic
Author

Jsoup's getelementbyid not working in asynctask

tasos georgiou
Greenhorn

Joined: Nov 30, 2012
Posts: 8
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
Marshal

Joined: Mar 22, 2005
Posts: 42040
    
  64
is JSoup supposed to be fully compatible with Android?


Ping & DNS - my free Android networking tools app
tasos georgiou
Greenhorn

Joined: Nov 30, 2012
Posts: 8
Ulf Dittmer wrote:is JSoup supposed to be fully compatible with Android?


As far as i know it is.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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...


Steve
tasos georgiou
Greenhorn

Joined: Nov 30, 2012
Posts: 8
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
Marshal

Joined: Mar 22, 2005
Posts: 42040
    
  64
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

Joined: Nov 30, 2012
Posts: 8
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

Joined: Nov 30, 2012
Posts: 8
That was it.I was getting the mobile version of the page where the specific elementID didn' exist.Thanks again.
 
GeeCON Prague 2014
 
subject: Jsoup's getelementbyid not working in asynctask