I want an alertDialog with multi choices items (items from my DB), but when I use it, I have this error: "android.database.CursorIndexOutOfBoundsException: Index 2 requested, with a size of 2".
My code to get data from db:
public Cursor getAllData() {
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select * from "+TABLE_NAME_2,null);
return res;
}
My DB:
public static final String TABLE_NAME_2 = "word_table";
public static final String COL1_1 = "ID";
public static final String COL1_2 = "NAME";
public static final String COL1_3 = "VALUE";
public static final String COL1_4 = "ISSELECTED";
db.execSQL("create table " + TABLE_NAME_2 +" (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,VALUE TEXT,ISSELECTED INTEGER)");
My code using multichoiceit
Cursor res = db.getAllData();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMultiChoiceItems(res,res.getString(3),res.getString(1),new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface parent, int position,
boolean checked) {
}
});
builder.setCancelable(true);
builder.setTitle(title);
builder.show();
error message (I have only 2 records in my db):
android.database.CursorIndexOutOfBoundsException: Index 2 requested, with a size of 2
thank a lot for your help!