android - java.lang.IllegalStateException: couldn't move cursor to position n -
i tying import contacts , display in listview
. here cursor loader
contentresolver cr = getactivity().getcontentresolver(); cursor cur = cr.query(contactscontract.contacts.content_uri, null, null, null, contactscontract.commondatakinds.phone.display_name + " asc"); madapter = new contactsadapter(getactivity(), cur, true, null); setlistadapter(madapter);
and adapter
for (cursor.movetofirst(); !cursor.isafterlast(); cursor.movetonext()) { // need cursor here string name = cursor.getstring(cursor.getcolumnindex(contactscontract.commondatakinds.phone.display_name)); log.e("name", name + "\n" + cursor.getcount()); names.add(name); } getindexlist();
and bindview
@override public void bindview(view view, context context, cursor cursor) { // gets handles individual view resources final viewholder holder = (viewholder) view.gettag(); string displayname = cursor.getstring(cursor.getcolumnindex(contactscontract.contacts.display_name)); string id = cursor.getstring(cursor.getcolumnindex(contactscontract.contacts._id)); (phonecursor.movetofirst(); !phonecursor.isafterlast(); phonecursor.movetonext()) { // need cursor here string phonenum = phonecursor.getstring(phonecursor.getcolumnindex(contactscontract.commondatakinds.phone.number)); log.e("phonenum", phonenum); mcheckbox.settag(phonenum); if (selectednums.contains(phonenum)) { mcheckbox.setchecked(true); } else { mcheckbox.setchecked(false); } }
my code crashes when listview
reaches end. if there 2 contacts getting error java.lang.illegalstateexception: couldn't move cursor position 2 , case if have n contacts. have seen this question couldn't find answer there. please help
here log
------------- beginning of crash 04-19 14:56:41.583 28188-28188/in.nuventure.com.wedding e/androidruntime: fatal exception: main process: in.nuventure.com.wedding, pid: 28188 java.lang.illegalstateexception: couldn't move cursor position 2 @ android.support.v4.widget.cursoradapter.getview(cursoradapter.java:248) @ android.widget.abslistview.obtainview(abslistview.java:2347) @ android.widget.listview.makeandaddview(listview.java:1864) @ android.widget.listview.filldown(listview.java:698) @ android.widget.listview.fillfromtop(listview.java:759) @ android.widget.listview.layoutchildren(listview.java:1659) @ android.widget.abslistview.onlayout(abslistview.java:2151) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.widget.framelayout.layoutchildren(framelayout.java:579) @ android.widget.framelayout.onlayout(framelayout.java:514) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.widget.framelayout.layoutchildren(framelayout.java:579) @ android.widget.framelayout.onlayout(framelayout.java:514) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.widget.linearlayout.setchildframe(linearlayout.java:1703) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1557) @ android.widget.linearlayout.onlayout(linearlayout.java:1466) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.support.design.widget.coordinatorlayout.layoutchild(coordinatorlayout.java:1037) @ android.support.design.widget.coordinatorlayout.onlayoutchild(coordinatorlayout.java:747) @ android.support.design.widget.coordinatorlayout.onlayout(coordinatorlayout.java:761) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.support.v4.widget.drawerlayout.onlayout(drawerlayout.java:1043) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.widget.framelayout.layoutchildren(framelayout.java:579) @ android.widget.framelayout.onlayout(framelayout.java:514) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.widget.linearlayout.setchildframe(linearlayout.java:1703) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1557) @ android.widget.linearlayout.onlayout(linearlayout.java:1466) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.widget.framelayout.layoutchildren(framelayout.java:579) @ android.widget.framelayout.onlayout(framelayout.java:514) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.widget.linearlayout.setchildframe(linearlayout.java:1703) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1557) @ android.widget.linearlayout.onlayout(linearlayout.java:1466) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.widget.framelayout.layoutchildren(framelayout.java:579) @ android.widget.framelayout.onlayout(framelayout.java:514) @ android.view.view.layout(view.java:15671) @ android.view.viewgroup.layout(viewgroup.java:5038) @ android.view.viewrootimpl.performlayout(viewrootimpl.java:2086) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1843) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1061) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5885) @ android.view.choreographer$callbackrecord.run(choreographer.java:767) @ android.view.choreographer.docallbacks(choreographer.java:580) @ android.view.choreographer.doframe(choreographer.java:550) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:753) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:135) @ android.app.acti 04-19 14:56:47.361 28188-28200/in.nuventure.com.wedding w/cursorwrapperinner: cursor finalized without prior close()
i couldn't find error line displayed. makes me confused
thanks help. issue getcount()
. did before , didn't notice later.
@override public int getcount() { return names.size(); }
i removed , works fine. help
Comments
Post a Comment