0
我正在解析一些歌詞網站,並且我從頭文件有錯誤。 URL,我給它(例如): http://www.azlyrics.com/lyrics/linkinpark/intheend.htmljava.io.IOException:連接上流的意外結束jsoup
class GetLyrics extends AsyncTask<String, Void, String> {
protected String doInBackground(String... urls) {
String url = urls[0];
String output;
output = "If you see this, some kind of error has occupied";
try {
Document document = Jsoup.connect(url).get(); //I dont know how it works, its google
document.outputSettings(new Document.OutputSettings().prettyPrint(false));//makes html() preserve linebreaks and spacing
document.select("br").append("\\n");
Elements lyrics = document.select("b + br + br + div"); //Search for lyrics <div> tag, that after <b> and 2 <br> tags
String s = lyrics.html().replaceAll("\\\\n", "\n"); //Google again
output = Jsoup.clean(s, "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false));
output = output.replace("\n\n", "\n");
output = output.substring(4); //Remove first enters
}
catch (HttpStatusException e) {
System.err.println("404 error: " + e);
System.err.println("Check your input data");
output = "An 404 error has occurred, more info:\n" + e + "\nCheck your input data";
Log.d("LyricFinder", e.toString());
}
catch (Exception e) {
System.err.println("Some error: " + e);
output = "An uknown error has occurred\nCheck your internet connection";
Log.d("LyricFinder", e.toString());
}
return output;
}
protected void onPostExecute(String lyrics) {
lyricsOutput.setText(lyrics);
}
} 和日誌是:
D/LyricFinder: java.io.IOException: unexpected end of stream on Connection{www.azlyrics.com:80, [email protected] hostAddress=85.17.159.246 cipherSuite=none protocol=http/1.1} (recycle count=0)
在Eclipse控制檯項目的代碼工作完美(但沒有這樣的AsyncTask:/ )
Idk該怎麼辦,因爲我的問題仍然沒有答案
嘿,那裏,我複製你的代碼,並在我的機器上運行它,它運行完美沒有任何錯誤。也許這是你的網址,你有問題?你可以嘗試運行你的代碼http://www.azlyrics.com/lyrics/linkinpark/intheend.html這個網址? –
[java.io.IOException:連接(Android,jsoup)上的流的意外結束的可能的重複](http://stackoverflow.com/questions/34073624/java-io-ioexception-unexpected-end-of-stream- on-connection-android-jsoup) –
@JoelMin它的幫助...可能是... java.lang.IllegalArgumentException:格式錯誤的URL:azlyrics.com/lyrics/linkinpark/intheend.html – Masafi