0
我想調試我遇到的問題。我正在使用以下代碼嘗試從頁面獲取圖像的鏈接。如何知道我的Jsoup元素是否正確選擇
private class DownloadWebpageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... args) {
String urls = args[0];
Document doc = null;
try {
doc = Jsoup.connect(urls).ignoreContentType(true).get();
image = doc.select("img[src~=(?i)\\.(png|jpe?g|gif)]").last();
theurlstring = "test " + image.attr("src"); // I put test here to make sure it is being executed
} catch (IOException e) {
e.printStackTrace();
}
return urls;
}
}
我通常收到一個錯誤,我試圖從元素「圖像」獲取鏈接。它說
Attempt to invoke virtual method 'java.lang.String org.jsoup.nodes.Element.attr(java.lang.String)' on a null object reference
所以有了這個錯誤,我現在認爲圖像沒有得到正確選擇。有人看到任何看起來錯誤的東西嗎?或者我怎麼能更好地查明問題?
這解決了嗎?否則請在下面的評論中發佈後續問題。 –