Android 游标和查询
案例R.id.buttonTest:{Android 游标和查询,android,Android,案例R.id.buttonTest:{ String[] projection = {DbTest.NAME}; String selection = "_id = ?"; String[] selectionArgs = { String.valueOf(1) }; Cursor c = sqdb.query(DbTest.TABLE_NAME,projection,selection,selectionArgs ,null,n
String[] projection = {DbTest.NAME};
String selection = "_id = ?";
String[] selectionArgs = { String.valueOf(1) };
Cursor c = sqdb.query(DbTest.TABLE_NAME,projection,selection,selectionArgs ,null,null,null);
String name = c.getString(c.getColumnIndex(DbTest.NAME));
textView1.setText(name);
}
break;
日志:
原因:android.database.CursorIndexOutOfBoundsException:请求索引-1,大小为1
有什么问题吗?我不明白。您首先需要使用:
c.moveToFirst()
这是因为在使用此命令之前,游标的索引是-1。您还可以使用结果(布尔值)确定游标是否为空。使用:
c.moveToFirst()
有关详细信息:
希望这有帮助您的答案有什么不同?非常感谢您的帮助。