【发布时间】:2012-01-31 08:25:38
【问题描述】:
我在 sqlite 中有一个表,它只包含一条记录,我想在游标中访问它,但遇到问题我得到了这个异常 java.lang.IllegalStateException: get field slot from row 0 col -1 failed
我的代码在这里:
c2=sql.dis();
c2.moveToFirst();
name = c2.getString(c2.getColumnIndex(DbManager.displayname));
ListName.setText("selected list"+name);
}
这在 BD 类中:
public Cursor dis() {
try
{
SQLiteDatabase db= this.getWritableDatabase();
String[] todo = new String[] {displayName };
Cursor cursor=db.query(displayname, todo, null, null, null,null, null);
return cursor;
}
catch(Exception ex)
{
str = ex.toString();
}
【问题讨论】:
-
检查光标长度以及它是否为空。 cursor.movetofirst 应该可以解决这个问题,但也可以使用它们
-
@Abhinav Singh Maurya 感谢您的评论只是发现我的错误我使用表名而不是列 ** name = c2.getString(c2.getColumnIndex(DbManager.displayname));** displayname its table不是列。现在它的工作:)
-
感谢@android-xx 指出,实际上我通过看到异常给出了答案,这就是为什么我评论它而不是作为答案发布我只是问这是否有帮助。恭喜你解决了这个问题
-
要么自己删除问题,要么自己回答并接受!!
标签: android sqlite android-layout