无法从 CursorWindow 读取第 0 行、第 -1 列

2024-03-12

我正在尝试获取表中的记录。我正在使用这个代码

        if(c!=null){
            if(c.moveToFirst()) {

                String tipId = c.getString(c.getColumnIndex(DAO.TIP_ID)).toString().trim();                 
                System.out.println("tipId: "+ tipId);

            }else{
                // Handle no rows returned
                System.out.println("Handle no rows returned");
            }
        }else{
            System.out.println("debug Cursor , cannot be created");
        }

但它给了我以下例外

Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.

它指的是那一行:

String tipId = c.getString(c.getColumnIndex(DAO.TIP_ID)).toString().trim();

希望有人能帮助我解决这个问题。 提前致谢。


在你的代码中

  c.getColumnIndex(DAO.TIP_ID)

返回-1。这意味着值DAO.TIP_ID与表的任何列名都不匹配。检查该值是否正确并与您正在访问的表的列名匹配

在导致问题的行之前添加以下行并在此处发布 Logcat 输出

 Log.v("out-data",DAO.TIP_ID+" "+c.getColumnIndex(DAO.TIP_ID)+" "+c.getColumnName(0));

(添加导入语句导入 android.util.Log;在你的开始 代码)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法从 CursorWindow 读取第 0 行、第 -1 列 的相关文章

随机推荐