在这行上,打开数据库:
dh.openDB(db);
这会将数据库的成员变量存储在中
DatabaseHelper.db(但其他位置,尤其是不在
Highscores.db)。然后,您致电:
dh.insert(x, y, db);
使用中的
null
db对象
Highscores。最后,在中
insert(),您可以使用以下
null
db对象:
return db.insert(TABLE, null, values);
相反,您应该使用以下
insert()方法作为方法:
public long insert(long score, int percentage) { // Remove db parameter ContentValues values = new ContentValues(); values.put(SCORE, score); values.put(PERCENTAGE, percentage); return db.insert(TABLE, null, values); // This will use the member variable}然后,
dh.insert(x, y);改为致电。
您还应该更改
openDB(SQLiteDatabasedb)为,
openDB()以便它可以写入正确的数据库。就目前而言,它只会覆盖局部变量的值(一旦函数作用域完成,它就不会改变)。



