我有一个有效的琐事游戏,现在正在尝试实现高分。我创建了一个扩展 SQLiteOpenHelper 的子类 DatabaseHelper 类。我试图从另一个类调用子类 DatabaseHelper 中的一个方法,但遇到错误。这些类不会编译,因此没有 LogCat 输出。我已经在代码中注释了错误。
代码结构建议也很受欢迎!
高分.java
public class Highscores extends Activity {
DatabaseHelper dh;
SQLiteDatabase db;
@Override
public void onCreate(Bundle savedInstanceState) {
dh = new DatabaseHelper(context);
}
public class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper(Context context) {
//code
}
public boolean check(long score, int percentage) {
//code
}
}
}
结果.java
public class Results extends Activity {
DatabaseHelper dh; //Error: "DatabaseHelper cannot be resolved to a type."
public void onCreate(Bundle savedInstanceState) {
dh = new DatabaseHelper(); //Error: "DatabaseHelper cannot be resolved to a type."
}
public void showResults() {
if(dh.check(score, percentage) == true) { //Error: "DatabaseHelper cannot be resolved to a type."
dh.insert(score, percentage); //Error: "DatabaseHelper cannot be resolved to a type."
}
}
}