我在创建数据库时总是遇到这个错误:
java.lang.IllegalArgumentException:版本必须 >= 版本 0 在 android.database.sqlite.SQLiteOpenHelper
任何想法如何解决这个问题。我的代码如下
public class DatabaseHandler extends SQLiteOpenHelper{
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "Exm";
private static final String KEY_ID = "id";
private static final String KEY_USERID = "userId";
private static final String KEY_USERNAME = "userName";
private static final String KEY_LOGINSTATUS = "userLoginStatus";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_USER + "("
+ KEY_ID + " INTEGER PRIMARY KEY ,"
+ KEY_USERID + " VARCHAR (32) ,"
+ KEY_USERNAME + " VARCHAR (50),"
+ KEY_LOGINSTATUS + " INTEGER" + ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER);
// Create tables again
onCreate(db);
}
}