Tushar Monirul
Tushar Monirul

Reputation: 5064

Jsoup java.io.EOFException in android

By using jsoup I am trying to get text from a link. But it always give me the end of the file error: java.io.EOFException in android. I have also tried jericho html parser but both of them are sending same error. Here is my code:

private class JsoupAsyncTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... params) {
            try {
                doc = Jsoup.connect("http://www.azlyrics.com/lyrics/adele/hello.html").get();
                htmlText = doc.body().text();
                Log.e("html text", "working");
            } catch (IOException e) {
                Log.e("html text", e.toString());
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            lyricsText.setText(htmlText);
        }
    }

I dont know why the error is happening. Please help me if anyone have any idea about it.

Upvotes: 1

Views: 343

Answers (1)

marcinj
marcinj

Reputation: 50046

Add user agent:

Document doc = Jsoup.connect("http://www.azlyrics.com/lyrics/adele/hello.html")
.userAgent("Mozilla").get();

Upvotes: 2

Related Questions