【问题标题】:Why do i get android.database.sqlite.sqlitecursor @ error为什么我得到 android.database.sqlite.sqlitecursor @ 错误
【发布时间】:2019-09-10 23:33:52
【问题描述】:

每当我尝试显示 nexpdate 的值时,我都会得到空值。我收到以下错误 android.database.sqlite.sqlitecursor @ .

  // insertion of values in renew table
public void insertrenew (String rcode, String nexpdate) {
            SQLiteDatabase db = this.getWritableDatabase();
            ContentValues contentValues = new ContentValues();
            contentValues.put("rcode", rcode);
            contentValues.put("nexpdate", nexpdate);
            db.insert("renew", null, contentValues);
        }

//java code to get the value of nexpdate 
public String  getrenew (String rcode) {
            SQLiteDatabase db = this.getReadableDatabase();
            String selectQuery = "SELECT nexpdate from renew where rcode = " + rcode;
            String cursor = String.valueOf(db.rawQuery(selectQuery, null));
            return cursor;

        }

【问题讨论】:

  • 你能分享你得到的确切错误吗?检查 logcat 输出并在此处分享。

标签: java android sqlite


【解决方案1】:

我假设您遇到了错误:

android.database.sqlite.sqlitecursor @ XXXX // where XXXX indicates object code

原因/详情:

出现在这里的原因是您将Cursor 对象直接转换为String,这就是问题所在!

String cursor = String.valueOf(db.rawQuery(selectQuery, null));

仅供参考,rawQuery() 方法实际上返回 Cursor 值,我们需要实际遍历游标以获取所需的数据。您可以参考How to retrieve data from cursor class 了解更多关于从光标获取数据的详细信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 2016-11-25
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多