java - Android acessing MainActivity from AsyncTask -


my application crashes after click button, code executes properly.

public void makelead(view v) throws exception {     try {        registertimer rt = new registertimer();        rt.ma = this;        rt.execute(null);     } catch (exception e) {         e.printstacktrace();     } } public void log(string msg) {     final textview tv = (textview)findviewbyid(r.id.edittext);     tv.append(msg); } private class registertimer extends asynctask {     public mainactivity ma;       @override     protected object doinbackground(object[] objects) {         ma.log("ausd");         return null;     } } 

makelead onclick event. method ma.log generates error works (msg added textedit). when delete ma.log, app doesn't crash. have no logs in androidstudio can't see error message. what's wrong ?

as described @raghunandan have not initialized ma.

next cannot access view in background thread.

if thread class inside of mainactivity class can use

runonuithread(new runnable() {              @override             public void run() {                 ma.log("ausd");              }         }); 

inside doinbackground method update view.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -