尝试创建sqlite数据库时,我收到以下LogCat异常:
Caused by: android.database.sqlite.sqliteException: Can’t upgrade read-only database from version 0 to 1
这是我的代码:
- import static android.provider.BaseColumns._ID;
- import static org.inetizen.university_tiMetable.Constants.DAY_OF_WEEK;
- import static org.inetizen.university_tiMetable.Constants.DURATION;
- import static org.inetizen.university_tiMetable.Constants.MODULE_CODE;
- import static org.inetizen.university_tiMetable.Constants.ROOM;
- import static org.inetizen.university_tiMetable.Constants.START_TIME;
- import static org.inetizen.university_tiMetable.Constants.TABLE_NAME;
- import static org.inetizen.university_tiMetable.Constants.TYPE_OF_SESSION;
- import android.content.Context;
- import android.database.sqlite.sqliteDatabase;
- import android.database.sqlite.sqliteOpenHelper;
- public class TiMetableData extends sqliteOpenHelper {
- private static final String DATABASE_NAME = "tiMetable.db";
- private static final int DATABASE_VERSION = 1;
- /** Create a helper object for the TiMetable database **/
- public TiMetableData(Context ctx) {
- super(ctx,DATABASE_NAME,null,DATABASE_VERSION);
- }
- @Override
- public void onCreate(sqliteDatabase db) {
- db.execsql("CREATE TABLE " + TABLE_NAME + " (" +_ID
- + " INTEGER PRIMARY KEY AUTOINCREMENT " + MODULE_CODE
- + " TEXT NOT NULL " + DAY_OF_WEEK + " TEXT NOT NULL "
- + START_TIME + " INTEGER NOT NULL " + DURATION
- + " INTEGER NOT NULL " + TYPE_OF_SESSION + " TEXT NOT NULL "
- + ROOM + " TEXT NOT NULL )");
- }
- @Override
- public void onUpgrade(sqliteDatabase db,int oldVersion,int newVersion) {
- db.execsql("DROP TABLE IF EXISTS " + TABLE_NAME);
- onCreate(db);
- }
- }
这是我的LogCat:
06001
有关如何解决异常的任何建议?