请任何人解释一下为什么我的数据库助手类中的这个方法不能正常工作。我使用一个布局列来查询一个名为“教程”的表。
public String getLayout(int layout_position)
{
String SQL = "SELECT * FROM Tutorial";
Cursor cursor = database.rawQuery(SQL, null);
cursor.moveToFirst();
cursor.move(layout_position);
String layout = cursor.getString(cursor.getColumnIndex("layout"));
System.out.println(">>>DBhelper->getLayout: "+ layout);
return (layout);
}游标由int layout_position移动,每次调用该方法之前都会递增。在layout_position达到2之前,一切实际上都很正常。
07-20 09:35:41.479: E/AndroidRuntime(4630): android.database.CursorIndexOutOfBoundsException: Index 2 requested, with a size of 2教程表预先填充了4行,所以我不确定这里发生了什么?
发布于 2014-07-20 07:54:35
cursor.move按参数中指定的数量移动游标位置。您很可能在寻找cursor.moveToPosition(layout_position)
https://stackoverflow.com/questions/24848471
复制相似问题