sqlite - Not displaying the records from the ListView with ArrayList in Android -
i want populate listview saved data database, can't retrieve data instead i'm getting first record , count of records itself.
mainactivity.java
//populating listview arraylist<hashmap<string, string>> mylistdata = new arraylist<hashmap<string, string>>(); int[] columnids = new int[] {r.id.tv_lastname, r.id.tv_firstname, r.id.tv_mi, r.id.tv_birthdate, r.id.tv_homeno, r.id.tv_mobile, r.id.tv_email, r.id.tv_brgy}; arraylist<string> arraypatientdata = db.arraylistpatientdata(); cursor cursor = db.getpatientdata(); for(int i=0; i<cursor.getcount(); i++) { hashmap<string,string> map = new hashmap<string, string>(); for(int j=0; j<arraypatientdata.size(); j++) { cursor cursorpatientdata = db.getpatientdata(j); //cursor cursorcitydata = db.getcitydata(); //cursor cursorprovincedata = db.getprovincedata(); firstname = cursorpatientdata.getstring(cursorpatientdata.getcolumnindex(constants.patient_fname)); lastname = cursorpatientdata.getstring(cursorpatientdata.getcolumnindex(constants.patient_lname)); middlename = cursorpatientdata.getstring(cursorpatientdata.getcolumnindex(constants.patient_mname)); bday = cursorpatientdata.getstring(cursorpatientdata.getcolumnindex(constants.patient_birthday)); homeno = cursorpatientdata.getstring(cursorpatientdata.getcolumnindex(constants.patient_home_no)); mobileno = cursorpatientdata.getstring(cursorpatientdata.getcolumnindex(constants.patient_mob_no)); email = cursorpatientdata.getstring(cursorpatientdata.getcolumnindex(constants.patient_email)); brgy = cursorpatientdata.getstring(cursorpatientdata.getcolumnindex(constants.patient_brgy)); //city = cursorcitydata.getstring(cursorcitydata.getcolumnindex(constants.city_id)); //province = cursorprovincedata.getstring(cursorprovincedata.getcolumnindex(constants.province_id)); map.put(firstname, firstname); map.put(lastname, lastname); map.put(middlename, middlename); map.put(bday, bday); map.put(homeno, homeno); map.put(mobileno, mobileno); map.put(email, email); map.put(brgy, brgy); //map.put(city, city); //map.put(province, province); } mylistdata.add(map); } simpleadapter arrayadapter = new simpleadapter(getapplicationcontext(), mylistdata, r.layout.attribute_patient, new string[] {firstname, lastname, middlename, bday, homeno, mobileno, email, brgy} , columnids); lv_patient.setadapter(arrayadapter);
databasehandler.java
public cursor getpatientdata(int _id) { sqlitedatabase db = this.getreadabledatabase(); cursor c = db.query(constants.table_patient, new string[] { constants.patient_id, constants.patient_fname, constants.patient_lname, constants.patient_mname, constants.patient_birthday, constants.patient_home_no, constants.patient_mob_no, constants.patient_email, constants.patient_brgy, constants.f_patient_city_id, constants.f_patient_province_id}, constants.patient_id + "=?", new string[] {string.valueof(_id)}, null, null, null); if (c != null) { c.movetofirst(); } db.close(); return c; } //get user data public cursor getpatientdata() { sqlitedatabase db = this.getreadabledatabase(); cursor c = db.query(constants.table_patient, new string[] { constants.patient_id, constants.patient_fname, constants.patient_lname, constants.patient_mname, constants.patient_birthday, constants.patient_home_no, constants.patient_mob_no, constants.patient_email, constants.patient_brgy, constants.f_patient_city_id, constants.f_patient_province_id}, null, null, null, null, null); if (c != null) { c.movetofirst(); } db.close(); return c; }
logcat:
07-24 18:31:29.585: e/androidruntime(14671): fatal exception: main 07-24 18:31:29.585: e/androidruntime(14671): java.lang.runtimeexception: unable start activity componentinfo{com.example.palsproject/com.example.palsproject.s_5th_search_patient}: android.database.cursorindexoutofboundsexception: index 0 requested, size of 0 07-24 18:31:29.585: e/androidruntime(14671): @ android.app.activitythread.performlaunchactivity(activitythread.java:1970) 07-24 18:31:29.585: e/androidruntime(14671): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1995) 07-24 18:31:29.585: e/androidruntime(14671): @ android.app.activitythread.access$600(activitythread.java:128) 07-24 18:31:29.585: e/androidruntime(14671): @ android.app.activitythread$h.handlemessage(activitythread.java:1161) 07-24 18:31:29.585: e/androidruntime(14671): @ android.os.handler.dispatchmessage(handler.java:99) 07-24 18:31:29.585: e/androidruntime(14671): @ android.os.looper.loop(looper.java:137) 07-24 18:31:29.585: e/androidruntime(14671): @ android.app.activitythread.main(activitythread.java:4514) 07-24 18:31:29.585: e/androidruntime(14671): @ java.lang.reflect.method.invokenative(native method) 07-24 18:31:29.585: e/androidruntime(14671): @ java.lang.reflect.method.invoke(method.java:511) 07-24 18:31:29.585: e/androidruntime(14671): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:790) 07-24 18:31:29.585: e/androidruntime(14671): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:557) 07-24 18:31:29.585: e/androidruntime(14671): @ dalvik.system.nativestart.main(native method) 07-24 18:31:29.585: e/androidruntime(14671): caused by: android.database.cursorindexoutofboundsexception: index 0 requested, size of 0 07-24 18:31:29.585: e/androidruntime(14671): @ android.database.abstractcursor.checkposition(abstractcursor.java:400) 07-24 18:31:29.585: e/androidruntime(14671): @ android.database.abstractwindowedcursor.checkposition(abstractwindowedcursor.java:136) 07-24 18:31:29.585: e/androidruntime(14671): @ android.database.abstractwindowedcursor.getstring(abstractwindowedcursor.java:50) 07-24 18:31:29.585: e/androidruntime(14671): @ com.example.palsproject.s_5th_search_patient.oncreate(s_5th_search_patient.java:66) 07-24 18:31:29.585: e/androidruntime(14671): @ android.app.activity.performcreate(activity.java:4465) 07-24 18:31:29.585: e/androidruntime(14671): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1053) 07-24 18:31:29.585: e/androidruntime(14671): @ android.app.activitythread.performlaunchactivity(activitythread.java:1934) 07-24 18:31:29.585: e/androidruntime(14671): ... 11 more
Comments
Post a Comment