android - Error while fetching data in ListView in dialog box? -


i trying fetch data though json in listview. problem when dialog open first time show listview correct data when close dialog , try open again give me error.

error is:

java.lang.illegalstateexception: content of adapter has changed listview did not receive notification. make sure content of adapter not modified background thread, ui thread. make sure adapter calls notifydatasetchanged() when content changes

i modify adapter ui thread of asynctast , call notifydatasetchanged() method ui thread. don't know why opening dialog box second time give me error.

so how can solve problem?

this onpostexecute method of asynctast:

@override protected void onpostexecute(string result) {     super.onpostexecute(result);     pdialog.dismiss();     planlist.clear();     applist.clear();     try {         jsonobject obj = new jsonobject(result);          string errcode = obj.getstring("errcode");          if(errcode.equalsignorecase("-1")){             jsonobject object = obj.getjsonobject("scheme");             jsonobject object1 = object.getjsonobject("mobile");             string state = object1.getstring("state");             string operator = object1.getstring("operator");             string operator_imag = object1.getstring("operator_img");             system.out.println("lenghtsima>>>>"+(object1.length()-3)+"");             numberofplans = (object1.length())-3;              for(int = positioninnumber; i<=positioninnumber;i++) {                 //  system.out.println("object>>>>"+object1.length()+" objectdata>>"+object1.getjsonobject(integer.tostring(i)));                 jsonobject object2 = object1.getjsonobject(integer.tostring(i));                 string plan_name = object2.getstring("plan_name");                 string plan_id = object2.getstring("plan_id");                 string operator_plan_id = object2.getstring("operator_plan_id");                  app_detail = new hashmap<string, string>();                 app_detail.put("plan_name",plan_name);                 app_detail.put("plan_id",plan_id);                 app_detail.put("operator_plan_id", operator_plan_id);                 applist.add(app_detail);                  jsonarray jsonarray = object2.getjsonarray("planlists");                 for(int j = 0; j<jsonarray.length();j++) {                     //    system.out.println("array>>"+jsonarray.length()+" jsonarray="+jsonarray.tostring());                     jsonobject object3 = jsonarray.getjsonobject(j);                     jsonobject object4 = object3.getjsonobject("opreatorplan");                     string amount = object4.getstring("amount");                     string id = object4.getstring("id");                     string description = object4.getstring("description");                     string validity = object4.getstring("talk_time");                     string recommend_flag = object4.getstring("recommend_flag");                      plan_details = new hashmap<string, string>();                     plan_details.put("amount",amount);                     plan_details.put("id",id);                     plan_details.put("description",description);                     plan_details.put("validity",validity);                     plan_details.put("recommend_flag",recommend_flag);                     planlist.add(plan_details);                  }             }         }         system.out.println("apppppp=" + planlist.tostring());          dialog();      } catch (exception e) {         e.printstacktrace();     }  } 

this adapter:

 private class adapterr extends baseadapter {          arraylist<hashmap<string, string>> list1;         context context;         public adapterr(context context,arraylist<hashmap<string, string>> applist){             this.list1 = applist;             this.context = context;         }          @override         public int getcount() {             return list1.size();         }          @override         public object getitem(int position) {             return list1.get(position);         }          @override         public long getitemid(int position) {             return position;         }          @override         public view getview(final int position, view convertview, viewgroup parent) {             final layoutinflater inflater = getlayoutinflater();             final myviewholdertwo myviewholdertwo;             if(convertview==null){                 convertview = inflater.inflate(r.layout.operator_plans,parent,false);                 myviewholdertwo = new myviewholdertwo(convertview);                 convertview.settag(myviewholdertwo);             }else{                 myviewholdertwo = (myviewholdertwo) convertview.gettag();             }              hashmap<string, string> map = list1.get(position);             string amount = map.get("amount");         //    string id = map.get("id");             string description = map.get("description");             string validity = map.get("validity");          //   string recommend_flag = map.get("recommend_flag");              myviewholdertwo.amount.settext(amount);             myviewholdertwo.validity.settext(validity);             myviewholdertwo.description.settext(description);               return convertview;         }     }      private class myviewholdertwo {         textview amount,validity,description;          public myviewholdertwo(view item) {             amount = (textview)item.findviewbyid(r.id.amount);             validity = (textview)item.findviewbyid(r.id.validity);             description = (textview)item.findviewbyid(r.id.description);         }     } 

this dialog:

 public void dialog(){         dlg = new dialog(browseoperatorsplans.this);         dlg.requestwindowfeature(window.feature_no_title);         dlg.setcontentview(r.layout.browse_operator_plans_dialog);         textview dialog_header = (textview)dlg.findviewbyid(r.id.dialog_header_title);         imageview close = (imageview)dlg.findviewbyid(r.id.close_dialog);           listview1 = (listview)dlg.findviewbyid(r.id.listview_horizontal);          adapterr = new adapterr(getbasecontext(),planlist);         listview1.setadapter(adapterr);         adapterr.notifydatasetchanged();       //  listview1.requestlayout();          close.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 dlg.dismiss();             }         });          dlg.getwindow().setlayout(windowmanager.layoutparams.match_parent, 500);         dialog_header.settext("select plan");         dlg.getwindow().setbackgrounddrawable(                 new colordrawable(                         android.graphics.color.transparent));         dlg.show();      } 

this logcat:

01-16 18:47:21.302 30604-30604/com.example.admin.smsrupee e/androidruntime: fatal exception: main     process: com.example.admin.smsrupee, pid: 30604     java.lang.illegalstateexception: content of adapter has changed listview did not receive notification. make sure content of adapter not modified background thread, ui thread. make sure adapter calls notifydatasetchanged() when content changes. [in listview(2131558551, class android.widget.listview) adapter(class com.example.admin.smsrupee.browseoperatorsplans$adapter)]         @ android.widget.listview.layoutchildren(listview.java:1565)         @ android.widget.abslistview.ontouchup(abslistview.java:3843)         @ android.widget.abslistview.ontouchevent(abslistview.java:3604)         @ android.view.view.dispatchtouchevent(view.java:7782)         @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2316)         @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2013)         @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2322)         @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2027)         @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2322)         @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2027)         @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2322)         @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2027)         @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2322)         @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2027)         @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2322)         @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2027)         @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2322)         @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2027)         @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2322)         @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2027)         @ com.android.internal.policy.impl.phonewindow$decorview.superdispatchtouchevent(phonewindow.java:2109)         @ com.android.internal.policy.impl.phonewindow.superdispatchtouchevent(phonewindow.java:1541)         @ android.app.activity.dispatchtouchevent(activity.java:2491)         @ android.support.v7.internal.view.windowcallbackwrapper.dispatchtouchevent(windowcallbackwrapper.java:60)         @ com.android.internal.policy.impl.phonewindow$decorview.dispatchtouchevent(phonewindow.java:2057)         @ android.view.view.dispatchpointerevent(view.java:7973)         @ android.view.viewrootimpl$viewpostimeinputstage.processpointerevent(viewrootimpl.java:4549)         @ android.view.viewrootimpl$viewpostimeinputstage.onprocess(viewrootimpl.java:4420)         @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3966)         @ android.view.viewrootimpl$inputstage.ondelivertonext(viewrootimpl.java:4016)         @ android.view.viewrootimpl$inputstage.forward(viewrootimpl.java:3985)         @ android.view.viewrootimpl$asyncinputstage.forward(viewrootimpl.java:4092)         @ android.view.viewrootimpl$inputstage.apply(viewrootimpl.java:3993)         @ android.view.viewrootimpl$asyncinputstage.apply(viewrootimpl.java:4149)         @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3966)         @ android.view.viewrootimpl$inputstage.ondelivertonext(viewrootimpl.java:4016)         @ android.view.viewrootimpl$inputstage.forward(viewrootimpl.java:3985)         @ android.view.viewrootimpl$inputstage.apply(viewrootimpl.java:3993)         @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3966)         @ android.view.viewrootimpl.deliverinputevent(viewrootimpl.java:6298)         @ android.view.viewrootimpl.doprocessinputevents(viewrootimpl.java:6261)         @ android.view.viewrootimpl.enqueueinputevent(viewrootimpl.java:6215)         @ android.view.viewrootimpl$windowinputeventreceiver.oninputevent(viewrootimpl.java:6443)         @ android.view.inputeventreceiver.dispatchinputevent(inputeventreceiver.java:185)         @ android.os.messagequeue.nativepollonce(native method)         @ android.os.messagequeue.next(messagequeue.java:138)         @ android.os.looper.loop(looper.java:150)         @ android.app.activitythread.main(activitythre 01-16 18:48:10.828 30604-30676/com.example.admin.smsrupee d/dalvikvm: threadid=15: exiting 01-16 18:48:10.829 30604-30676/com.example.admin.smsrupee d/dalvikvm: threadid=15: detach (group=0x4183bce0) 01-16 18:48:10.829 30604-30676/com.example.admin.smsrupee d/dalvikvm: threadid=15: removing list 01-16 18:48:10.830 30604-30676/com.example.admin.smsrupee d/dalvikvm: threadid=15: bye! 01-16 18:52:21.343 30604-30604/com.example.admin.smsrupee i/p 

the problem keep reference planlist in adapterr class, when call planlist.clear() method, exception thrown. so, instantiate adapter each time when call dialog() method, can avoid keeping reference planlist in adapterr class, example, this:

    public adapterr(context context,arraylist<hashmap<string, string>> applist){         this.list1 = new arraylist<hashmap<string, string>>(applist);         this.context = context;     } 

and should work expected


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -