java - 为什么即使在 moveToNext() 之类的调用之后,android SQLite 光标仍位于位置 -1?
问题描述
这段代码曾经可以工作,但现在当我进入 for 循环中的 Cursor.get 方法时,我得到:
android.database.CursorIndexOutOfBoundsException:请求索引-1,大小为5
Cursor.getCount() 方法大于零,但光标仍不移动。
我正在使用 SQLiteAssetHelper。这是我的代码:
ArrayList<Profile> GetAllProfiles() throws SQLiteException{
SQLiteDatabase database = this.getReadableDatabase();
String[] selection = {COL_ID, COL_NAME, COL_IMAGE};
Cursor c = database.query(TABLE_PLAYERS, selection, null, null, null, null, null);
ArrayList<Profile> profiles = new ArrayList<>();
int colIndexID = c.getColumnIndex(COL_ID);
int colIndexName = c.getColumnIndex(COL_NAME);
int colIndexImage = c.getColumnIndex(COL_IMAGE);
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
{
profiles.add(new Profile(
c.getInt(colIndexID),
c.getString(colIndexName),
c.getBlob(colIndexImage)));
}
database.close();
return profiles;
}
解决方案
推荐阅读
- javascript - 如何在没有图像的 react-native 中制作像这样的自定义剪切布局组件?
- flutter - 如何在颤振中在 MultipartRequest 上插入标头
- python - 使用python和beautifulsoup在HTML中搜索特定的字符串格式给定的字符串没有标签或标识符
- css - 基于长按单击的填充圆形 Svg 描边动画
- json - 将数组值作为单个对象输出
- python - 二分搜索与线性搜索奇怪的时间
- r - rstanarm中的多logit回归
- python - 使用 python-pptx 操作 PowerPoint XML 时查找子元素是否存在
- css - 有没有人想出在使用 Deno 时在 React 组件中使用 CSS 的最佳方法?
- kotlin - Kotlin:如何从片段导航到活动