错误:无法从 CursorWindow 读取第 0 行,第 -1 列.在访问数据之前确保 Cursor 已正确初始化 [英] ERROR: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is correctly initialized before accessing data

查看:34
本文介绍了错误:无法从 CursorWindow 读取第 0 行,第 -1 列.在访问数据之前确保 Cursor 已正确初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a very simple database android app. It takes an input and display result. Add button is used to add the input and delete button for deleting the input stored in SQLite database. My cursor in Android SQLite is pointed correctly but still I am facing the error: Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. Following is the cursor part: 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;

我尝试更改光标位置,但仍然出现相同的错误.我在其他网站上研究过,概念也是一样,但仍然存在问题.

I have tried changing cursor positions but still same error appearing. I have researched on other sites and same is the concept but still there is an issue.

推荐答案

显然,结果集中没有 studentname 列,如果 c.getColumnIndex("studentname") 正在返回 -1.

Apparently, there is no studentname column in your result set, if c.getColumnIndex("studentname") is returning -1.

这篇关于错误:无法从 CursorWindow 读取第 0 行,第 -1 列.在访问数据之前确保 Cursor 已正确初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆