Android 光标索引问题

Android 光标索引问题,android,sqlite,cursor,Android,Sqlite,Cursor,谁能解释一下为什么我的数据库助手类中的这个方法不能正常工作。我使用布局列查询名为Tutorial的表 光标按int layout_位置移动,每次调用该方法之前,该位置都会递增。在布局位置达到2之前,一切都正常工作。然后我从logcat得到这个错误 教程表预先填充了4行,所以我不确定这里发生了什么?cursor.move按参数中指定的量移动光标位置。您很可能正在查找cursor.moveToPositionlayout\u position请求的索引2,大小为2:这意味着查询结果中只有2行。 pu

谁能解释一下为什么我的数据库助手类中的这个方法不能正常工作。我使用布局列查询名为Tutorial的表

光标按int layout_位置移动,每次调用该方法之前,该位置都会递增。在布局位置达到2之前,一切都正常工作。然后我从logcat得到这个错误


教程表预先填充了4行,所以我不确定这里发生了什么?

cursor.move按参数中指定的量移动光标位置。您很可能正在查找cursor.moveToPositionlayout\u position

请求的索引2,大小为2:这意味着查询结果中只有2行。
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);
}
07-20 09:35:41.479: E/AndroidRuntime(4630): android.database.CursorIndexOutOfBoundsException: Index 2 requested, with a size of 2