2013-06-02 17 views
0

這是我的方法的高分當選擇光標SQL得到強制關閉

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山坳 - 1 ??我無法理解

回答

1

您收到此錯誤的原因是你的查詢只返回TIME列。你必須修改你的查詢來說SELECT MIN(TIME), MOVE, GRID FROM HIGHSCORE3;返回你正在尋找的所有列。

希望這會有所幫助。 :)

+0

thx我知道了,當我在w3schools.com上測試時,我看到只有1列被選中,所以即時通過ASC使用順序,我得到了該表中的最小值,但現在我正在考慮獲得最小值2列參數'TIME'和'MOVE' – user2375628

+0

我明白了,'select min(time),min(move)from highscore3' 但是,我不能像往常一樣調用name列,必須'getnameindex(0)';當我看到在w3school.com列名更改爲'expr1000' – user2375628

0

請更改表格中列time的名稱,然後檢索數據。因爲這是已存儲在database schema內部的密鑰。請更改列的名稱並再次檢查一切。我希望它能正常工作。

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(); 

    }