CursorIndexOutOfBoundsException problem:Index 4 requested, with a size of 4

南楼画角 提交于 2019-12-02 04:27:13

Array indexing starts with 0, not 1. your fourth element is stored at index 3.

When i put cur.moveToPosition(index); under String description = cur.getString(cur.getColumnIndexOrThrow("description")); i have Index -1 requested, with a size of 4 otherwise, like above code Index 4 requested, with a size of 4

When the row set is first returned the cursor will be at positon -1, which is before the first row.

just after calling
Cursor cur = db.query(true, TABLE_COORD, result_columns, null, null, null, null, null, null);

your cursor will be at -1 position and this exception will come if you fetch data when cursor is on -1 index.
when you are calling cur.moveToPosition(index-1); for the first time your index value may be 0 that is the issue.

The error is, certainly in code String description = cur.getString(cur.getColumnIndexOrThrow("description")); because you have not got such column . You have only COL_DESCRI column, which probably does not match "description"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!