android - Asynctask jsoup nullpointer exception -
this question has answer here:
- what nullpointerexception, , how fix it? 12 answers
public class asynctask extends asynctask <void, string, void > { string title; @override protected void doinbackground(void... params) { try { document document = jsoup.connect(url).get(); title = document.title(); } catch (ioexception e) { e.printstacktrace(); } return null; } @override protected void onpostexecute(void result) { textview campotesto = (textview) findviewbyid(r.id.text); campotesto.settext(title); } }}
every time run nullpointer exception on settext line , on line in create asynctask class
pass title in doinbackground() onpostexecute();
try this:
public class asynctask extends asynctask <void, string, string> { string title; @override protected string doinbackground(void... params) { try { document document = jsoup.connect(url).get(); title = document.title(); } catch (ioexception e) { e.printstacktrace(); } return title; } @override protected void onpostexecute(string title) { textview campotesto = (textview) findviewbyid(r.id.text); campotesto.settext(title); } }
Comments
Post a Comment