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

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

问题描述

我创建了一个非常简单数据库的android应用.它接受输入并显示结果.添加按钮用于添加输入,删除按钮用于删除存储在SQLite数据库中的输入.我在Android SQLite中的 cursor 被正确指向,但仍然遇到错误:原因:java.lang.IllegalStateException:无法从CursorWindow读取行0,col -1.在从游标访问数据之前,请确保已正确初始化游标.以下是游标部分: 光标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.

推荐答案

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

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

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

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