0

/データベース作成コード/

public static final String QUESTION_TABLE_NAME = "mythquizq";
public static final String QUESTION_COLUMN_ID = "_id";
public static final String QUESTION_COLUMN_MYTHQUIZ = "question";
public static final String QUESTIONSTATUS_COLUMN_MYTHQUIZ = "played";

private static final String QUESTION_DATABASE_NAME = "mythquizq.db";
private static final int QUESTION_DATABASE_VERSION= 1;


private static final String QUESTION_TABLE_CREATE = "create table "
      + QUESTION_TABLE_NAME + "(" + QUESTION_COLUMN_ID
      + " integer primary key autoincrement, " 
      + QUESTION_COLUMN_MYTHQUIZ + " text not null, "  
      + QUESTIONSTATUS_COLUMN_MYTHQUIZ + " boolean );";


public QuestionDatabaseCreation(Context context) {
    super(context, QUESTION_DATABASE_NAME, null, QUESTION_DATABASE_VERSION );
  }



@Override
public void onCreate(SQLiteDatabase database) {

database.execSQL(QUESTION_TABLE_CREATE);

      }

/データ取得コード/

private SQLiteDatabase qdatabase;
private SQLiteDatabase adatabase;
private QuestionDatabaseCreation questionHelper;
private String questioncolumnname=QuestionDatabaseCreation.QUESTION_COLUMN_MYTHQUIZ;
private String questionstatus=QuestionDatabaseCreation.QUESTIONSTATUS_COLUMN_MYTHQUIZ;
private String[] FROMQ = {QuestionDatabaseCreation.QUESTION_COLUMN_MYTHQUIZ};


public String getQuestion(){

String q="";
Cursor qcursor=qdatabase.query(QuestionDatabaseCreation.QUESTION_TABLE_NAME, FROMQ, questionstatus + "==" +false,null, null, null, null, null);
update(0);
q= qcursor.getString(0);
return q;

}

/* ログキャット */

  10-08 17:37:14.400: E/AndroidRuntime(1436): FATAL EXCEPTION: main
    10-08 17:37:14.400: E/AndroidRuntime(1436): java.lang.RuntimeException: Unable to start activity
    ComponentInfo{com.example.mythologicalquiz/com.example.mythologicalquiz.Question1}: android.database.sqlite.SQLiteException: 
no such column: false (code 1): ,
 while compiling:SELECT question FROM mythquizq WHERE played==false
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.os.Handler.dispatchMessage(Handler.java:99)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.os.Looper.loop(Looper.java:137)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.app.ActivityThread.main(ActivityThread.java:5041)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at java.lang.reflect.Method.invokeNative(Native Method)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at java.lang.reflect.Method.invoke(Method.java:511)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at dalvik.system.NativeStart.main(Native Method)
    10-08 17:37:14.400: E/AndroidRuntime(1436): Caused by: android.database.sqlite.SQLiteException: no such column: false (code 1): , while compiling: SELECT question FROM mythquizq WHERE played==false
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1238)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at com.example.DatabaseHelper.DatabaseRetreiveUpdate.getQuestion(DatabaseRetreiveUpdate.java:87)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at com.example.mythologicalquiz.Question1.onCreate(Question1.java:38)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.app.Activity.performCreate(Activity.java:5104)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    10-08 17:37:14.400: E/AndroidRuntime(1436):     ... 11 more
    10-08 17:37:15.200: D/dalvikvm(1436): GC_CONCURRENT freed 199K, 12% free 2583K/2924K, paused 10ms+148ms, total 633ms
    10-08 17:37:19.320: I/Process(1436): Sending signal. PID: 1436 SIG: 9
4

1 に答える 1

3

falseネイティブの SQLite データ型ではありません。代わりに、integerwhile 0meansfalseおよび1meansに変換されtrueます。==Java では一般的ですが、SQL では一般的ではないため、where 句を次のように変更します。

questionstatus + " = 0"

booleana を準備済みステートメントにバインドするたびに、への変換integerが自動的に行われます。この場合、where 句は SQL の一部であるため、false解釈されませんでした。

詳細については、 SQLite データ型を確認してください。

于 2013-10-08T19:03:35.127 に答える