さて、私のタイトルはそれを言っていると思います...次のコードを使用して:
public int getCorrectAnswersPrev(int level, String player) {
int count = 0;
level = level - 1;
Cursor c = myDataBase.rawQuery(
"SELECT COUNT(*) FROM ANSWERS WHERE LEVEL =" + level
+ " AND ANSWERCORRECT = 1 AND PLAYER=" + player, null);
c.moveToFirst();
count = c.getInt(0);
c.close();
myDataBase.close();
return count;
}
プレイヤーが特定の質問に答えなかったことがあるので、レベルの最初に特定のアイテムがないことを意味します...カウントを0として初期化しますが、このエラーが発生しますが、それでも実行されることを理解していますクエリを実行し、エラーを返します。しかし、データベースにアイテムがない場合にこれを防ぐ方法はありますか?
編集:
11-16 13:34:30.188: E/AndroidRuntime(10206): FATAL EXCEPTION: main
11-16 13:34:30.188: E/AndroidRuntime(10206): android.database.sqlite.SQLiteException: no such column: Bog: , while compiling: SELECT COUNT(*) FROM ANSWERS WHERE LEVEL =1 AND ANSWERCORRECT = 1 AND PLAYER=Bog
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
11-16 13:34:30.188: E/AndroidRuntime(10206): at com.hup.game.db.DataBaseHelper.getCorrectAnswers(DataBaseHelper.java:251)
11-16 13:34:30.188: E/AndroidRuntime(10206): at com.hup.game.LevelSelectorAdapter.getView(LevelSelectorAdapter.java:75)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.widget.AbsListView.obtainView(AbsListView.java:1432)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.widget.GridView.onMeasure(GridView.java:935)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.view.View.measure(View.java:8319)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.view.View.measure(View.java:8319)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.view.View.measure(View.java:8319)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.view.View.measure(View.java:8319)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.os.Handler.dispatchMessage(Handler.java:99)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.os.Looper.loop(Looper.java:130)
11-16 13:34:30.188: E/AndroidRuntime(10206): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-16 13:34:30.188: E/AndroidRuntime(10206): at java.lang.reflect.Method.invokeNative(Native Method)
11-16 13:34:30.188: E/AndroidRuntime(10206): at java.lang.reflect.Method.invoke(Method.java:507)
11-16 13:34:30.188: E/AndroidRuntime(10206): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:861)
11-16 13:34:30.188: E/AndroidRuntime(10206): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:619)
11-16 13:34:30.188: E/AndroidRuntime(10206): at dalvik.system.NativeStart.main(Native Method)