我创建了 DBAdapter 类,它负责建立与数据库的连接并执行任何查询并最终关闭连接。
我有另一个类,它不是从 Activity 类继承的( ReminderBeep ),但我必须在这个类中使用我的DBAdapter。
实际上我不知道如何操纵DBAdapter构造函数来建立连接。*
错误是:构造函数DBAdapter(ReminderBeep)未定义
DBAdapter是:
public class DBAdapter {
static final String DATABASE_NAME = "MyDB";
static final int DATABASE_VERSION = 2;
final Context context;
DatabaseHelper DBHelper;
SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
}
}
//---opens the database---
public DBAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
//---closes the database---
public void close()
{
DBHelper.close();
}
public void insert(String sql)
{
db.execSQL(sql);
}
}
BeepReminder是:
public class ReminderBeep
{
public void DeleteDailyActivities()
{
DBAdapter db=new DBAdapter(this);
db.open();
String sql="delete from DailyWorks";
db.insert(sql);
db.close();
}
}
答案 0 :(得分:2)
提醒提示音不会延长活动。但DB Adapter希望将Context作为参数,
DBAdapter db=new DBAdapter(this);
this
指的是ReminderBeep