android - Index 2 requested with size of 2 -



android - Index 2 requested with size of 2 -

i newbie android development , here first project of gridview database. show error "index 2 requested size of 2"

i using sqlite database db file

here code

please help me!!!!!

public class mainactivity extends activity { sqlitedatabase mydb; gridview data; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); info = (gridview) findviewbyid(r.id.gridview1); list<string> li = new arraylist<string>(); arrayadapter<string> dataadapter = new arrayadapter<string>( getapplicationcontext(), android.r.layout.simple_spinner_dropdown_item, li); dataadapter.setdropdownviewresource(r.layout.activity_main); seek { mydb = openorcreatedatabase(getstring(r.string._sdcard_sales_db), mode_private, null); cursor cr = mydb.rawquery("select * users", null); if (cr != null) { if (cr.movetofirst()) { { string desc = cr.getstring(cr.getcolumnindex("user")); li.add(desc); } while (cr.movetonext()); toast.maketext(getapplicationcontext(), cr.getstring(cr.getcolumnindex("user")), toast.length_long).show(); } else { toast.maketext(getapplicationcontext(), "no data", toast.length_long).show(); } } cr.close(); mydb.close(); } grab (exception e) { toast.maketext(getapplicationcontext(), "error" + e.getmessage(), toast.length_long).show(); } }}

thanks in advance

do { string desc = cr.getstring(cr.getcolumnindex("user")); li.add(desc); } while (cr.movetonext()); toast.maketext(getapplicationcontext(), cr.getstring(cr.getcolumnindex("user")), toast.length_long).show();

after do-while loop, cursor cr points row after lastly valid row.

remove toast phone call getstring() invalid cursor index, or alter toast info want.

android eclipse sqlite indexing size

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -