android - Asynctask jsoup nullpointer exception -


this question has answer here:

 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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -