好的,所以我现在真的很困惑。我正在尝试向我的程序添加一个新表,但每当我这样做时,我都会崩溃,特别是在 onCreate 方法中。我不知道为什么。有什么建议么?
这也是我得到的一个错误,但我在任何地方都找不到 categories.db
引起:android.database.sqlite.SQLiteException:没有这样的表:categories.db(代码1):,编译时:SELECT * FROM categories.db
private final static int DB_VERSION = 2;
public static String TABLE_NAME = "players";
public static String DB_NAME = "playerslist.db";
public static String SCORE = "score";
public static String ID = "_id";
public static String PLAYER_NAME = "name";
public static String CATEGORY_TABLE_NAME = "categories";
public static String CATEGORY_NAME = "category_name";
public static String CATEGORY_VALUE = "category_value";
public static String CATEGORY_ID = "category_id";
public static String CATEGORY_PLAYER_ID = "category_player_id";
public static String CREATE_PLAYER_TABLE = "CREATE TABLE "+TABLE_NAME+" ("+ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+PLAYER_NAME+" TEXT, "+
SCORE+" TEXT)";
public static String CREATE_CATEGORY_TABLE = "CREATE TABLE "+CATEGORY_TABLE_NAME+"("+CATEGORY_ID+" INTEGER" +
"PRIMARY KEY AUTOINCREMENT, "+CATEGORY_NAME+" TEXT, "+CATEGORY_VALUE+" INTEGER, "
+CATEGORY_PLAYER_ID+" INTEGER)";
public SQLHelp(Context context) {
super(context, DB_NAME, null, 2);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_PLAYER_TABLE);
db.execSQL(CREATE_CATEGORY_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
for(int i = oldVersion; i < newVersion; i++){
switch(i){
case 1:
db.execSQL(CREATE_CATEGORY_TABLE);
break;
}
}
}