0

I want to parse an HTML page in order to get the first.jpg link, and setting its link to a WebView, in order to view the image on the app. I use AsyncTask. It seems to work, but I encounter an exception on the Try block. On the LogCat it's just shown ERROR PARSING ERROR (as you can see, that's how I chosen in the Catch group). But no explanation on what causes the exception. The code is as follows:

@Override
    protected String doInBackground(String... params) {
        TextView prova = (TextView)findViewById(R.id.searchedName);
        Document doc;
        try {
            doc = Jsoup.connect("[url]http://www.lolking.net/summoner/euw/42997801")
                     .userAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22")
                     .timeout(3000).get();
            String icon = doc.select("img[src$=.jpg]").first().text();
            WebView summonerIcon = (WebView)findViewById(R.id.webView1);
            summonerIcon.loadUrl(icon);
        } catch (Exception e) {
            Log.e("ERROR", "PARSING ERROR");
    }
    return null;

    }
5
  • e.printStackTrace(); in catch block will give you more details Commented Oct 1, 2013 at 11:54
  • apart from the answers posted you are also updating uo doInbackground which is wrong. Do it in onPostexecute Commented Oct 1, 2013 at 11:58
  • But no explanation on what causes the exception because you don't log any. Commented Oct 1, 2013 at 12:03
  • @Raghunandan I've applyed your changes, but it seems like jsoup can't parse the image URL, because I've tried to setText on a TextView with its URL but it goes blank... Did I something wrong while catching the url? Commented Oct 1, 2013 at 12:35
  • @user2834656 check your jsoup parsing. can you post which html tag you are parsing? Commented Oct 1, 2013 at 12:54

5 Answers 5

1
String icon = doc.select("img[src$=.jpg]").first().text();

will fetch the text in <img> tag.

Your code should read as below.

String icon = doc.select("img[src$=.jpg]").first().attr("src");
Sign up to request clarification or add additional context in comments.

Comments

0

You can use:

Log.e("ERROR", "PARSING ERROR", e);

In order to log also the message e holds.

Comments

0

connect expects a valid URL. Remove the "[url]" String in the method argument

Document doc = Jsoup.connect("http://www.lolking.net/summoner/euw/42997801")

Comments

0

You cannot manipulate Views inside a non-UI thread - in this case AsyncTask. This might be causing problem:

TextView prova = (TextView)findViewById(R.id.searchedName);
...
WebView summonerIcon = (WebView)findViewById(R.id.webView1);
summonerIcon.loadUrl(icon);

Comments

0

are you giving the permission of accessing internet in android maniefest file like this in your maniefest file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.