android - 来自 CursorWindow 的错误 : Couldn't read row 0, col -1。在访问数据之前确保 Cursor 被正确初始化

标签 android android-studio sqlite android-sqlite

我创建了一个非常简单的数据库 android 应用程序。它接受输入并显示结果。添加按钮用于添加输入,删除按钮用于删除存储在 SQLite 数据库中的输入。我在 Android SQLite 中的 cursor 指向正确,但我仍然面临错误:Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow。在从中访问数据之前,请确保 Cursor 已正确初始化。 以下是游标部分: 游标 c = db.rawQuery(query, null);

    c.moveToFirst();

    //Traversing through DB
    while (!c.isAfterLast()){
        if(c.getString(c.getColumnIndex("studentname")) !=null)
        {
            dbString += c.getString(c.getColumnIndex("studentname"));
            dbString +="\n"; }

        c.moveToNext(); }
        db.close();

        return dbString;

我已经尝试更改光标位置,但仍然出现相同的错误。我在其他网站上进行了研究,概念相同,但仍然存在问题。

最佳答案

显然,如果 c.getColumnIndex("studentname") 返回 -1,则您的结果集中没有 studentname 列。

关于android - 来自 CursorWindow 的错误 : Couldn't read row 0, col -1。在访问数据之前确保 Cursor 被正确初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38819232/

相关文章:

android - 底部带有进度条的无尽 RecyclerView

android - 现在如何将 Eclipse 项目导入 Android Studio?

java - 由于 JDK 错误,无法安装 Android Studio

sql - 如何在不读取 BLOB 内容的情况下获取 BLOB 的大小

SQLite - GROUP BY 行,仅当某些列与另一列匹配时

java.lang.IllegalStateException : [TextView] must not be null

android - 如何获得 Android Touch 事件(运动事件)的开始和结束坐标?

git - 使用Android studio推送到云服务时出现"Please generate new Identifier"错误

android - 如何从模拟器中删除数据库?

android 应用程序出现在手机的 Google Play 中,但平板电脑上没有