原因:android.database.sqlite.SQLiteException:无法将只读数据库从版本0升级到1

前端之家收集整理的这篇文章主要介绍了原因:android.database.sqlite.SQLiteException:无法将只读数据库从版本0升级到1前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
尝试创建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

有关如何解决异常的任何建议?

解决方法

您使用的sql语法看起来不正确,您缺少逗号.试试这个: 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)“);
原文链接:https://www.f2er.com/android/315192.html

猜你在找的Android相关文章