android - New AsyncTask correction, app crash -


please, can correct code? i'm getting crazy. app crashes, code seems good. want display progress dialog during pi calculation. reference of strings or order of params? (or incorrect calculation of pi?).

new asynctask<void, void, string>() {     progressdialog dialog;      @override     public void onpreexecute() {         dialog.setmessage("calculating...");         dialog.show();     }      @override     public string doinbackground(void... params) {          double max_num = 100000000;         double min_num = 1;         double = 0;          long starttime = system.currenttimemillis();         while (min_num < max_num) {             += 4 / min_num;             min_num += 2;             -= 4 / min_num;             min_num += 2;         }         long endtime = system.currenttimemillis();          long total_time = endtime - starttime;          string time = long.tostring(total_time);          return time;      }      @override     public void onpostexecute(string time) {          if (dialog.isshowing()) {             dialog.dismiss();              string ms = "ms";             textview time_txt = (textview) findviewbyid(r.id.time_txt);             textview finished = (textview) findviewbyid(r.id.finished);             textview time_ms = (textview) findviewbyid(r.id.time_ms);             finished.settext("finished!");             time_txt.settext("total time");             time_ms.settext(time + ms);         }     }  }.execute(); 

initialise dialog , problem solved this:

 @override  public void onpreexecute() {         dialog = new dialog(youractivity.this); //add line         dialog.setmessage("calculating...");         dialog.show();  } 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -