0

リストビューでクイズアプリのスコアを降順に表示しようとしています。何らかの理由でそれはしません。スコアは表示されますが、降順ではありません。スコアのすべての情報を取得するための DBAdapter スニペットは次のとおりです。

public Cursor getAllInfoScores()
             {
                return db.query(DATABASE_TABLE_HIGHSCORES, new String[] {ROW_ID, KEY_NAME, KEY_SCORES, KEY_DIFFICULTY},null,null,null,null, "scores DESC");

             }

私もこれを試しました:

 public Cursor getAllInfoScores()
             {
                return db.query(DATABASE_TABLE_HIGHSCORES, new String[] {"_id", "name", "scores", "difficulty"},null,null,null,null, "scores DESC");

             }

リストに表示しようとしているアクティビティは次のとおりです。

public class HighScores extends ListActivity{

DBAdapter db = new DBAdapter(this);
private Cursor mCursor;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.highscores);

    db.open();
    fillData();

}

private void fillData() {
    mCursor = db.getAllInfoScores();
    String[] from = new String[]{DBAdapter.KEY_NAME, DBAdapter.KEY_SCORES, DBAdapter.KEY_DIFFICULTY}; 
    int[] to = new int[]{R.id.textViewnamehs, R.id.textViewscorehs, R.id.textViewdiff};
   SimpleCursorAdapter c = 
            new SimpleCursorAdapter(this, R.layout.highscoresrow, mCursor, from, to);
setListAdapter(c);


}

エラー:

09-13 15:19:04.533: E/AndroidRuntime(12792): FATAL EXCEPTION: main
09-13 15:19:04.533: E/AndroidRuntime(12792): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dtan.mathwiz/com.dtan.mathwiz.HighScores}: android.database.sqlite.SQLiteException: near "scores": syntax error: , while compiling: select _id,name,scores,difficulty from highscores orderby scores desc
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.os.Looper.loop(Looper.java:123)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.app.ActivityThread.main(ActivityThread.java:3683)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at java.lang.reflect.Method.invokeNative(Native Method)
 09-13 15:19:04.533: E/AndroidRuntime(12792):   at java.lang.reflect.Method.invoke(Method.java:507)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at dalvik.system.NativeStart.main(Native Method)
09-13 15:19:04.533: E/AndroidRuntime(12792): Caused by: android.database.sqlite.SQLiteException: near "scores": syntax error: , while compiling: select _id,name,scores,difficulty from highscores orderby scores desc
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
0 9-13 15:19:04.533: E/AndroidRuntime(12792):   at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at com.dtan.mathwiz.adapter.DBAdapter.getAllInfoScores(DBAdapter.java:138)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at com.dtan.mathwiz.HighScores.fillData(HighScores.java:29)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at com.dtan.mathwiz.HighScores.onCreate(HighScores.java:24)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-13 15:19:04.533: E/AndroidRuntime(12792):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-13 15:19:04.533: E/AndroidRuntime(12792):    ... 11 more
4

2 に答える 2

1

クエリを見ているとKEYWORD ORDER BY

そのはず

ORDER BYまたorder by

そしてそうではない

orderby
于 2012-09-13T07:36:33.607 に答える
-1

ここに含める必要がORDERあるのは、使用できる単純な生のクエリです db.rawQuery("SELECT _id,name,scores,difficulty from YourTableName order scores desc")

于 2012-09-13T07:04:10.643 に答える