android - update Database with JSON class crashing -


the update class crashing cant open it, , didn't understan logcat:

07-17 19:28:22.115: d/dalvikvm(3799): gc_for_alloc freed 133k, 23% free 12979k/16808k, paused 254ms, total 278ms 07-17 19:28:22.623: d/dalvikvm(3799): gc_for_alloc freed 15k, 15% free 14345k/16808k, paused 58ms, total 58ms 07-17 19:28:22.666: i/dalvikvm-heap(3799): grow heap (frag case) 16.517mb 2514028-byte allocation 07-17 19:28:22.863: d/dalvikvm(3799): gc_for_alloc freed <1k, 13% free 16800k/19264k, paused 192ms, total 192ms 07-17 19:28:23.003: d/dalvikvm(3799): gc_concurrent freed 0k, 13% free 16800k/19264k, paused 8ms+24ms, total 147ms 07-17 19:28:23.133: d/dalvikvm(3799): gc_for_alloc freed 1380k, 13% free 16801k/19264k, paused 57ms, total 58ms 07-17 19:28:23.173: i/dalvikvm-heap(3799): grow heap (frag case) 18.916mb 2514028-byte allocation 07-17 19:28:23.443: d/dalvikvm(3799): gc_concurrent freed <1k, 12% free 19256k/21720k, paused 109ms+10ms, total 269ms 07-17 19:28:28.693: d/androidruntime(3799): shutting down vm 07-17 19:28:28.703: w/dalvikvm(3799): threadid=1: thread exiting uncaught exception (group=0x40a71930) 07-17 19:28:28.786: e/androidruntime(3799): fatal exception: main 07-17 19:28:28.786: e/androidruntime(3799): android.os.networkonmainthreadexception 07-17 19:28:28.786: e/androidruntime(3799):     @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1117) 07-17 19:28:28.786: e/androidruntime(3799):     @ java.net.inetaddress.lookuphostbyname(inetaddress.java:385) 07-17 19:28:28.786: e/androidruntime(3799):     @ java.net.inetaddress.getallbynameimpl(inetaddress.java:236) 07-17 19:28:28.786: e/androidruntime(3799):     @ java.net.inetaddress.getallbyname(inetaddress.java:214) 07-17 19:28:28.786: e/androidruntime(3799):     @ org.apache.http.impl.conn.defaultclientconnectionoperator.openconnection(defaultclientconnectionoperator.java:137) 07-17 19:28:28.786: e/androidruntime(3799):     @ org.apache.http.impl.conn.abstractpoolentry.open(abstractpoolentry.java:164) 07-17 19:28:28.786: e/androidruntime(3799):     @ org.apache.http.impl.conn.abstractpooledconnadapter.open(abstractpooledconnadapter.java:119) 07-17 19:28:28.786: e/androidruntime(3799):     @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:360) 07-17 19:28:28.786: e/androidruntime(3799):     @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:555) 07-17 19:28:28.786: e/androidruntime(3799):     @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:487) 07-17 19:28:28.786: e/androidruntime(3799):     @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:465) 07-17 19:28:28.786: e/androidruntime(3799):     @ com.example.ahliaevents.jsonparser.makehttprequest(jsonparser.java:62) 07-17 19:28:28.786: e/androidruntime(3799):     @ com.example.ahliaevents.editcard$getcarddetails$1.run(editcard.java:131) 07-17 19:28:28.786: e/androidruntime(3799):     @ android.os.handler.handlecallback(handler.java:725) 07-17 19:28:28.786: e/androidruntime(3799):     @ android.os.handler.dispatchmessage(handler.java:92) 07-17 19:28:28.786: e/androidruntime(3799):     @ android.os.looper.loop(looper.java:137) 07-17 19:28:28.786: e/androidruntime(3799):     @ android.app.activitythread.main(activitythread.java:5041) 07-17 19:28:28.786: e/androidruntime(3799):     @ java.lang.reflect.method.invokenative(native method) 07-17 19:28:28.786: e/androidruntime(3799):     @ java.lang.reflect.method.invoke(method.java:511) 07-17 19:28:28.786: e/androidruntime(3799):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 07-17 19:28:28.786: e/androidruntime(3799):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 07-17 19:28:28.786: e/androidruntime(3799):     @ dalvik.system.nativestart.main(native method) 07-17 19:28:33.943: i/process(3799): sending signal. pid: 3799 sig: 9 

i didn't understand whats written in logcat. has had same problem before?

this code

public class editcard extends activity {      edittext txtname;     edittext txtposition;     edittext txtcollege;     edittext txtphone;     button btnsave;     button btndelete;      string cid;      // progress dialog     private progressdialog pdialog;      // json parser class     jsonparser jsonparser = new jsonparser();      // single product url     private static final string url_card_details = "http://xxx";      // url update product     private static final string url_update_card = "http://xxx";      // url delete product     private static final string url_delete_card = "http://xxx";      // json node names     private static final string tag_success = "success";     private static final string tag_cards = "cards";     private static final string tag_cid = "cid";     private static final string tag_cname = "name";     private static final string tag_position = "position";     private static final string tag_college = "college";     private static final string tag_phone = "phone";      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.edit_card);          // save button         btnsave = (button) findviewbyid(r.id.savecard);         btndelete = (button) findviewbyid(r.id.deletecard);          // getting product details intent         intent = getintent();          // getting product id (pid) intent         cid = i.getstringextra(tag_cid);          // getting complete product details in background thread         new getcarddetails().execute();          // save button click event         btnsave.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view arg0) {                 // starting background task update product                 new savecarddetails().execute();             }         });          // delete button click event         btndelete.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view arg0) {                 // deleting product in background thread                 new deletecard().execute();             }         });      }      /**      * background async task complete product details      * */     class getcarddetails extends asynctask<string, string, string> {          /**          * before starting background thread show progress dialog          * */         @override         protected void onpreexecute() {             super.onpreexecute();             pdialog = new progressdialog(editcard.this);             pdialog.setmessage("loading card details. please wait...");             pdialog.setindeterminate(false);             pdialog.setcancelable(true);             pdialog.show();         }          /**          * getting product details in background thread          * */         protected string doinbackground(string... params) {              // updating ui background thread             runonuithread(new runnable() {                 public void run() {                     // check success tag                     int success;                     try {                         // building parameters                         list<namevaluepair> params = new arraylist<namevaluepair>();                         params.add(new basicnamevaluepair("cid", cid));                          // getting product details making http request                         // note product details url use request                         jsonobject json = jsonparser.makehttprequest(                                 url_card_details, "get", params);                          // check log json response                         log.d("single product details", json.tostring());                          // json success tag                         success = json.getint(tag_success);                         if (success == 1) {                             // received product details                             jsonarray cardobj = json                                     .getjsonarray(tag_cards); // json array                              // first product object json array                             jsonobject card = cardobj.getjsonobject(0);                              // product pid found                             // edit text                             txtname = (edittext) findviewbyid(r.id.editcard1);                             txtposition = (edittext) findviewbyid(r.id.editcard2);                             txtcollege= (edittext) findviewbyid(r.id.editcard3);                             txtphone= (edittext) findviewbyid(r.id.editcard4);                              // display product data in edittext                             txtname.settext(card.getstring(tag_cname));                             txtposition.settext(card.getstring(tag_position));                             txtcollege.settext(card.getstring(tag_college));                             txtphone.settext(card.getstring(tag_phone));                          }else{                             // product pid not found                         }                     } catch (jsonexception e) {                         e.printstacktrace();                     }                 }             });              return null;         }           /**          * after completing background task dismiss progress dialog          * **/         protected void onpostexecute(string file_url) {             // dismiss dialog once got details             pdialog.dismiss();         }     }      /**      * background async task  save product details      * */     class savecarddetails extends asynctask<string, string, string> {          /**          * before starting background thread show progress dialog          * */         @override         protected void onpreexecute() {             super.onpreexecute();             pdialog = new progressdialog(editcard.this);             pdialog.setmessage("saving card ...");             pdialog.setindeterminate(false);             pdialog.setcancelable(true);             pdialog.show();         }          /**          * saving product          * */         protected string doinbackground(string... args) {              // getting updated data edittexts             string name = txtname.gettext().tostring();             string position = txtposition.gettext().tostring();             string college = txtcollege.gettext().tostring();             string phone = txtphone.gettext().tostring();              // building parameters             list<namevaluepair> params = new arraylist<namevaluepair>();             params.add(new basicnamevaluepair("name", name));             params.add(new basicnamevaluepair("position", position));             params.add(new basicnamevaluepair("college", college));             params.add(new basicnamevaluepair("phone", phone));              // sending modified data through http request             // notice update product url accepts post method             jsonobject json = jsonparser.makehttprequest(url_update_card,                     "post", params);              // check json success tag             try {                 int success = json.getint(tag_success);                  if (success == 1) {                     // updated                     intent = getintent();                     // send result code 100 notify product update                     setresult(100, i);                     finish();                 } else {                     // failed update product                 }             } catch (jsonexception e) {                 e.printstacktrace();             }              return null;         }           /**          * after completing background task dismiss progress dialog          * **/         protected void onpostexecute(string file_url) {             // dismiss dialog once product uupdated             pdialog.dismiss();         }     }      /*****************************************************************      * background async task delete product      * */     class deletecard extends asynctask<string, string, string> {          /**          * before starting background thread show progress dialog          * */         @override         protected void onpreexecute() {             super.onpreexecute();             pdialog = new progressdialog(editcard.this);             pdialog.setmessage("deleting product...");             pdialog.setindeterminate(false);             pdialog.setcancelable(true);             pdialog.show();         }          /**          * deleting product          * */         protected string doinbackground(string... args) {              // check success tag             int success;             try {                 // building parameters                 list<namevaluepair> params = new arraylist<namevaluepair>();                 params.add(new basicnamevaluepair("cid", cid));                  // getting product details making http request                 jsonobject json = jsonparser.makehttprequest(                         url_delete_card, "post", params);                  // check log json response                 log.d("delete card", json.tostring());                  // json success tag                 success = json.getint(tag_success);                 if (success == 1) {                     // product deleted                     // notify previous activity sending code 100                     intent = getintent();                     // send result code 100 notify product deletion                     setresult(100, i);                     finish();                 }             } catch (jsonexception e) {                 e.printstacktrace();             }              return null;         }          /**          * after completing background task dismiss progress dialog          * **/         protected void onpostexecute(string file_url) {             // dismiss dialog once product deleted             pdialog.dismiss();          }      } } 

this code check out don't know whats wrong it

you getting networkonmainthreadexception. doing network related operation on ui thread.

use thread or use asynctask.

the exception thrown when application attempts perform networking operation on main thread. thrown applications targeting honeycomb sdk or higher.

http://developer.android.com/reference/android/os/asynctask.html

you can check tutorial

http://www.vogella.com/articles/androidbackgroundprocessing/article.html


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -