无法从CursorWindow读取第0行,列-1 [英] Couldn't read row 0, col -1 from CursorWindow
问题描述
我正在尝试在表中获取记录.我正在使用此代码
I'm trying to get records in my table. I'm using this code
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");
}
但这给了我以下例外情况
But it gives me the following exception
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();
希望有人帮我解决这个问题. 预先感谢.
hope anyone helps me to fix this. Thanks in advance.
推荐答案
在您的代码中
c.getColumnIndex(DAO.TIP_ID)
返回-1 .这意味着 DAO.TIP_ID 的值与表的任何列名都不匹配.请检查该值是否正确并与您正在访问的表的列名相匹配
is returning -1. This means value of DAO.TIP_ID doesnot match with any column name of table .Check if this value is correct and matches with a column name of the table you are accessing
在引起问题的行之前添加以下行,并在此处发布Logcat输出
add following line before the line which causes problem and post the Logcat output here
Log.v("out-data",DAO.TIP_ID+" "+c.getColumnIndex(DAO.TIP_ID)+" "+c.getColumnName(0));
(在您的开头添加导入语句 import android.util.Log; 代码)
(add import statement import android.util.Log; in beginning of your code)
这篇关于无法从CursorWindow读取第0行,列-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!