データベース テーブルを作成しようとしているサービス (以下にリスト) があります。PlayerTable の onCreate() 内の sql が実行されたときに、理解できない例外が発生しています。すべてのコードを以下に示します。基本的に、サービスは起動し、SQLiteDatabase オブジェクトを取得します。これにより、ClueBuddyOpenHelper で onCreate() が呼び出され、PlayerTable で onCreate() が呼び出されます。SQLの実行時に例外が発生します。どんな助けでも大歓迎です。
06-03 00:47:43.043: E/AndroidRuntime(4347): FATAL EXCEPTION: IntentService[NewGameService]
06-03 00:47:43.043: E/AndroidRuntime(4347): android.database.sqlite.SQLiteException: near "android": syntax error
06-03 00:47:43.043: E/AndroidRuntime(4347): at android.database.sqlite.SQLiteStatement.native_executeSql(Native Method)
06-03 00:47:43.043: E/AndroidRuntime(4347): at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:90)
06-03 00:47:43.043: E/AndroidRuntime(4347): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1899)
06-03 00:47:43.043: E/AndroidRuntime(4347): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1839)
06-03 00:47:43.043: E/AndroidRuntime(4347): at ws.hamacher.cluebuddy.db.PlayerTable.onCreate(PlayerTable.java:32)
06-03 00:47:43.043: E/AndroidRuntime(4347): at ws.hamacher.cluebuddy.db.ClueBuddyOpenHelper.onCreate(ClueBuddyOpenHelper.java:30)
06-03 00:47:43.043: E/AndroidRuntime(4347): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:165)
06-03 00:47:43.043: E/AndroidRuntime(4347): at ws.hamacher.cluebuddy.service.NewGameService.onHandleIntent(NewGameService.java:18)
06-03 00:47:43.043: E/AndroidRuntime(4347): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
06-03 00:47:43.043: E/AndroidRuntime(4347): at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 00:47:43.043: E/AndroidRuntime(4347): at android.os.Looper.loop(Looper.java:137)
06-03 00:47:43.043: E/AndroidRuntime(4347): at android.os.HandlerThread.run(HandlerThread.java:60)
コード:
public class ClueBuddyOpenHelper extends SQLiteOpenHelper {
private static ClueBuddyOpenHelper instance = null;
private ClueBuddyOpenHelper(final Context context) {
super(context, context.getString(R.string.db_name), null, R.string.db_version);
}
public static ClueBuddyOpenHelper getInstance(Context context) {
if (instance == null) {
instance = new ClueBuddyOpenHelper(context.getApplicationContext());
}
return instance;
}
@Override
public void onOpen(final SQLiteDatabase db) {
super.onOpen(db);
}
@Override
public void onCreate(SQLiteDatabase db) {
PlayerTable.onCreate(db);
MoveTable.onCreate(db);
TurnTable.onCreate(db);
PersonTable.onCreate(db);
WeaponTable.onCreate(db);
RoomTable.onCreate(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
public class PlayerTable {
public static final String TABLE_NAME = "player";
public static class PlayerColumns {
public static final String PLAYER_ID = "player_id";
public static final String TOKEN = "token";
public static final String NUMBER_OF_CARDS = "number_of_cards";
public static final String USER_IS_PLAYER = "user_is_player";
public static final String ACTIVE = "active";
}
public static void onCreate(SQLiteDatabase db) {
StringBuilder sb = new StringBuilder("");
sb.append("CREATE TABLE ");
sb.append(PlayerTable.TABLE_NAME);
sb.append(" (");
sb.append(PlayerColumns.PLAYER_ID);
sb.append(" INTEGER PRIMARY KEY, ");
sb.append(PlayerColumns.TOKEN);
sb.append(" TEXT UNIQUE NOT NULL, ");
sb.append(PlayerColumns.NUMBER_OF_CARDS);
sb.append(" INTEGER NOT NULL, ");
sb.append(PlayerColumns.USER_IS_PLAYER);
sb.append(" TEXT, ");
sb.append(PlayerColumns.ACTIVE);
sb.append(" TEXT NOT NULL);");
db.execSQL(db.toString());
}
}
public class NewGameService extends IntentService {
public NewGameService() {
super("NewGameService");
}
@Override
protected void onHandleIntent(Intent intent) {
SQLiteDatabase db = ClueBuddyOpenHelper.getInstance(this).getWritableDatabase();
db.execSQL("DELETE FROM player;");
db.execSQL("DELETE FROM turn;");
db.execSQL("DELETE FROM move;");
db.execSQL("DELETE FROM person;");
db.execSQL("DELETE FROM weapon;");
db.execSQL("DELETE FROM room;");
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(BroadcastReceivers.NEW_GAME_BROADCAST_RECEIVER.getName());
//broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
sendBroadcast(broadcastIntent);
}
}