当选择光标sql得到强制关闭

时间:2013-06-02 06:37:19

标签: android sqlite cursor

这是我的方法高分

public void highscore(){

        Cursor gethighscorealter = highscoreDB.rawQuery("SELECT MIN(TIME) FROM HIGHSCORE3;"
                   , null);
        gethighscorealter.moveToFirst();
        if(gethighscorealter!=null){
            timer= gethighscorealter.getInt(gethighscorealter.getColumnIndex("TIME"));
            move = gethighscorealter.getInt(gethighscorealter.getColumnIndex("MOVE"));
            grid = gethighscorealter.getInt(gethighscorealter.getColumnIndex("GRID"));
            highscoreview();
        }
    }

这是我的日志猫

06-02 13:30:38.599: E/AndroidRuntime(32416): FATAL EXCEPTION: main
06-02 13:30:38.599: E/AndroidRuntime(32416): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
06-02 13:30:38.599: E/AndroidRuntime(32416):    at android.database.CursorWindow.nativeGetLong(Native Method)
06-02 13:30:38.599: E/AndroidRuntime(32416):    at android.database.CursorWindow.getLong(CursorWindow.java:507)
06-02 13:30:38.599: E/AndroidRuntime(32416):    at android.database.CursorWindow.getInt(CursorWindow.java:574)
06-02 13:30:38.599: E/AndroidRuntime(32416):    at android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java:69)
06-02 13:30:38.599: E/AndroidRuntime(32416):    at skripsi.slidame.PuzzleActivity.highscore(PuzzleActivity.java:253)
06-02 13:30:38.599: E/AndroidRuntime(32416):    at skripsi.slidame.PuzzleActivity.onOptionsItemSelected(PuzzleActivity.java:131)

他们说第0行col - 1 ??我无法理解

3 个答案:

答案 0 :(得分:1)

您收到此错误的原因是您的查询仅返回TIME列。您必须修改查询以说出SELECT MIN(TIME), MOVE, GRID FROM HIGHSCORE3;以返回您要查找的所有列。

希望这会有所帮助。 :)

答案 1 :(得分:0)

请从表中更改列time的名称,然后检索数据。因为这是已存储在database schema中的密钥。请更改列的名称,然后再次检查所有内容。我希望它能正常工作。

答案 2 :(得分:0)

我粗你的光标不计数然后抛出异常,

Cursor gethighscorealter = highscoreDB.rawQuery("SELECT MIN(TIME) FROM HIGHSCORE3;"
               , null);

    if(gethighscorealter.getCount() > 0){
        gethighscorealter.moveToFirst();
        timer= gethighscorealter.getInt(gethighscorealter.getColumnIndex("TIME"));
        move = gethighscorealter.getInt(gethighscorealter.getColumnIndex("MOVE"));
        grid = gethighscorealter.getInt(gethighscorealter.getColumnIndex("GRID"));
        highscoreview();
        gethighscorealter.close();

    }