Cargar documento en WebView con JSOUP
Estoy tratando de analizar una parte de la página web a WebView. Estoy usando la biblioteca jsoup para obtener parte de la página que necesito y luego cargarla en la vista web. Aquí está el código:
public void loadArticleWithHTML (){
Thread downloadThread = new Thread() {
public void run() {
try {
doc = Jsoup.connect("http://en.wikipedia.org/").get();
element = doc.select("#mp-itn b a");
} catch (java.io.IOException e){
e.printStackTrace();
}
}
};
downloadThread.start();
mWebView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), description, Toast.LENGTH_SHORT).show();
}
});
try {
mWebView.loadData(element.html(), "text/html", "UTF-8");
} catch (NullPointerException e){
e.printStackTrace();
Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_LONG).show();
}
}
Pero siempre recibo un error
Intente invocar el método virtual 'java.lang.String org.jsoup.select.Elements.html ()' en una referencia de objeto nulo