android - Error shows: FATAL EXCEPTION: AsyncTask #1 -


error shows: fatal exception: asynctask #1

public class newproductactivity extends activity {     private progressdialog pdialog;     jsonparser jsonparser = new jsonparser();     edittext inputname;     edittext inputprice;     edittext inputdesc;     private static string url_create_product = "http://127.0.0.1/android_connect/create_product.php";     private static final string tag_success = "success";     static list<string> citations = null;     @override     public void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);         setcontentview(r.layout.add_product);         inputname = (edittext) findviewbyid(r.id.inputname);         inputprice = (edittext) findviewbyid(r.id.inputprice);         inputdesc = (edittext) findviewbyid(r.id.inputdesc);         button btncreateproduct = (button) findviewbyid(r.id.btncreateproduct);              btncreateproduct.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view view) {                 // creating new product in background thread                 new createnewproduct().execute();             }         });     }      class createnewproduct extends asynctask<string, string, string> {          @override         protected void onpreexecute() {             super.onpreexecute();             pdialog = new progressdialog(newproductactivity.this);             pdialog.setmessage("creating product..");             pdialog.setindeterminate(false);             pdialog.setcancelable(true);             pdialog.show();         }         protected string doinbackground(string... args) {             string name = inputname.gettext().tostring();             string price = inputprice.gettext().tostring();             string description = inputdesc.gettext().tostring();             list<namevaluepair> params = new arraylist<namevaluepair>();             params.add(new basicnamevaluepair("name", name));             params.add(new basicnamevaluepair("price", price));             params.add(new basicnamevaluepair("description", description));             jsonobject json = jsonparser.makehttprequest(url_create_product,                     "post", params);             log.d("create response", json.tostring());             try {                 int success = json.getint(tag_success);                 if (success == 1) {                     intent = new intent(getapplicationcontext(), allproductsactivity.class);                     startactivity(i);                     finish();                 } else {                 }             } catch (jsonexception e) {                 e.printstacktrace();             }              return null;         }          protected void onpostexecute(string file_url) {             pdialog.dismiss();         }     } } 

move in onpostexecute(....)

 intent = new intent(getapplicationcontext(), allproductsactivity.class);  startactivity(i);  finish(); 

never call finish(); or intent in doinbackground(....)


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -