Cursor index out of bound exception on listview cllick event

*爱你&永不变心* 提交于 2019-12-02 13:13:05

Use one of the moveTo...() methods such as moveToFirst() on the Cursor before trying to access its column data. After the query, the cursor will be pointing to row index -1 which is not a valid row.

Also check the return value of the move to make sure the cursor is pointing to a valid row after the move.

For example,

Cursor c1 = db.rawQuery(sql, null);
if (c1.moveToFirst()) {
    int n = c1.getColumnIndex("description");
    data = c1.getString(n);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!