android - App crash when execute asynctask -


my app crash when execute asynctask. try send data android server app crashes when execute asynctask ` input input = new input(); input.execute();

    mainactivity = this;     latitude = "-6.711647";     longitude ="108.5413";`   public class input extends asynctask<string, string, string> {      hashmap<string, string> user = db.getuserdetails();     string email = user.get("email");     string success;      @override     protected void onpreexecute() {         super.onpreexecute();         pdialog = new progressdialog(mainactivity.this);         pdialog.setmessage("sending data server...");         pdialog.setindeterminate(false);         pdialog.show();     }       @override     protected string doinbackground(string... arg0) {         string stremail = email.tostring();         string strnama = latitude.tostring();         string strprodi = longitude.tostring();           list<namevaluepair> params = new arraylist<namevaluepair>();         params.add(new basicnamevaluepair("email", stremail));         params.add(new basicnamevaluepair("latitude", strnama));         params.add(new basicnamevaluepair("longitude", strprodi));           jsonobject json = jparser.makehttprequest(url, "post", params);          try {             success = json.getstring("success");          } catch (exception e) {             toast.maketext(getapplicationcontext(), "error",                     toast.length_long).show();         }         return null;     }     protected void onpostexecute(string file_url) {         // dismiss dialog once done         pdialog.dismiss();          if (success.equals("1"))          {             toast.maketext(getapplicationcontext(), "kirim data sukses!!!", toast.length_long).show();         }          else          {             toast.maketext(getapplicationcontext(), "kirim data gagal!!!", toast.length_long).show();          }     } } 

this complete code http://pastebin.com/jrdxeqkg , logcat http://prntscr.com/7p3vbz

the reference db null when call new input() in oncreate().

solution: initialize db before calling new input():

 db = new sqlitehandler(getapplicationcontext());  input input = new input(); 

by way, there many issues design point of view, solve (one of) crash(es).


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -