我创建了一个类来处理我的所有SQLite数据库访问。
以下是来源:
package za.co.myapps.testingdb;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBHelper {
private static final String DATABASE_NAME = "SampleCollector";
private static final int DATABASE_VERSION = 1;
static SQLiteDatabase db;
public DBHelper (Context context) {
myDBHelper openHelper = new myDBHelper(context);
DBHelper.db = openHelper.getWritableDatabase();
}
private class myDBHelper extends SQLiteOpenHelper {
myDBHelper (Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS TestTable(_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);");
}
@Override
public void onUpgrade (SQLiteDatabase db, int a, int b){
db.execSQL("DROP TABLE IF EXISTS TestTable");
onCreate(db);
}
}
}
当我在我的开始活动中创建DBHelper类的实例时,我收到一条错误,指出:无法打开数据库文件
我做错了什么?