java - Fetching Record from Local Database and Showing in Listview IllegalStateException: -


getting ids 1 table , matching table , getting record table.some time records in list when want insert 1 more record in list illegalexception not notified listview etc.

private void getallrecords() {      string cmpid = "";  //fetching ids table 1 one , passing id table     cursor preappointmentrecord = jasperdatabase.getinstance(preappointmentsactivity.this).getpreappointmentrecord();     preappointmentrecord.movetofirst();     if (preappointmentrecord.getcount() != 0) {         while (!preappointmentrecord.isafterlast()) {             cmpid = preappointmentrecord.getstring(1);             getallcompanyname(cmpid);             preappointmentrecord.movetonext();         }          preappointmentrecord.close();      } } private void getallcompanyname(string companyid) {     //fetching company names matched ids     cursor companynamecursor =    jasperdatabase.getinstance(preappointmentsactivity.this).getpreappointmentcompanies(companyid);     companynamecursor.movetofirst();     if (companynamecursor.getcount() != 0) {         while (!companynamecursor.isafterlast()) { //getting second string database                 recordsar.add(new preappointmentrecord(companynamecursor.getstring(2)));             companynamecursor.movetonext();         }         companynamecursor.close();     } } 

asynctask class calling getallrecords() function :

 protected void doinbackground(string[] paramarrayofstring) {         getallrecords();         return null;     }      protected void onpostexecute(void paramvoid) {         super.onpostexecute(paramvoid);         if (mprogressdialog.isshowing())             mprogressdialog.dismiss();    //notifying listview changing view             customrecordsadapter.notifydatasetchanged();     } 

customer adapter:

 @override     public view getview(final int i, view view, viewgroup viewgroup) {         final int k = 0 ;        //using getting record storing in recordarray         final preappointmentrecord prerecord = recordsar.get(i); 

logcat :

fatal exception: main process: com.jmd.jasper, pid: 11265                                                             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(2131558625, class android.widget.listview) adapter(class com.jmd.jasper.activities.preappointmentsactivity$customrecordsadapter)]                                                                 @ android.widget.listview.layoutchildren(listview.java:1566)                                                                 @ android.widget.abslistview.onlayout(abslistview.java:2564)                                                                 @ android.view.view.layout(view.java:15601)                                                                 @ android.view.viewgroup.layout(viewgroup.java:4881)                                                                 @ android.widget.relativelayout.onlayout(relativelayout.java:1055)                                                                 @ android.view.view.layout(view.java:15601)                                                                 @ android.view.viewgroup.layout(viewgroup.java:4881)                                                                 @ android.widget.framelayout.layoutchildren(framelayout.java:453)                                                                 @ android.widget.framelayout.onlayout(framelayout.java:388)                                                                 @ android.view.view.layout(view.java:15601)                                                                 @ android.view.viewgroup.layout(viewgroup.java:4881)                                                                 @ android.support.v7.internal.widget.actionbaroverlaylayout.onlayout(actionbaroverlaylayout.java:493)                                                                 @ android.view.view.layout(view.java:15601)                                                                 @ android.view.viewgroup.layout(viewgroup.java:4881)                                                                 @ android.widget.framelayout.layoutchildren(framelayout.java:453)                                                                 @ android.widget.framelayout.onlayout(framelayout.java:388)                                                                 @ android.view.view.layout(view.java:15601)                                                                 @ android.view.viewgroup.layout(viewgroup.java:4881)                                                                 @ android.widget.linearlayout.setchildframe(linearlayout.java:1677)                                                                 @ android.widget.linearlayout.layoutvertical(linearlayout.java:1531)                                                                 @ android.widget.linearlayout.onlayout(linearlayout.java:1440)                                                                 @ android.view.view.layout(view.java:15601)                                                                 @ android.view.viewgroup.layout(viewgroup.java:4881)                                                                 @ android.widget.framelayout.layoutchildren(framelayout.java:453)                                                                 @ android.widget.framelayout.onlayout(framelayout.java:388) 

customer adapter :

    private class customrecordsadapter extends baseadapter {         @override         public int getcount() {             return recordsar.size();         }          @override         public object getitem(int i) {             return null;         }          @override         public long getitemid(int i) {             return 0;         }          @override         public view getview(final int i, view view, viewgroup viewgroup) {             final int k = 0 ;              final preappointmentrecord prerecord = recordsar.get(i); //            final preappointmentcustomer1 prerecord1 = recordsar1.get(k);               view = view.inflate(preappointmentsactivity.this, r.layout.custom_record_list_preappointment, null);             textview companynametextview = (textview) view.findviewbyid(r.id.companynametextview);               companynametextview.settext(prerecord.companyname);     //            nametextview.settext(prerecord1.customerid);      return view;         }     } 

i had same problem, fixed using method

requestlayout();

from class listview

edit

mylistview.requestlayout(); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -