每当我尝试访问我的数据库时,都会出错。相同的代码在我的其他应用程序中运行完美。这是我的DataBase Helper Class的代码......
public class LocalDatabaseHelper extends SQLiteOpenHelper{
private static final String TAG = "LocalDataBaseHelper";
public String DB_PATH = "data/data/com.cybergeniesolutions.scentsysquirrel/databases/";
private static String DB_NAME = "local.db";
public static final String KEY_ROWID = "_id";
public static final String PERFUME_ID = "perfume_id";
public static final String GOT_IT = "got_it";
public static final String NAME = "name";
public static final String PHONE = "phone";
public static final String WEBSITE = "website";
public static final String FACEBOOK = "facebook";
public static final String RATING = "rating";
public static final String MY_CHOICES ="My_Choices";
public static final String RATINGS = "Ratings";
public static final String CONSULTANT_DETAILS = "Consultant_Details";
private static final int DATABASE_VERSION = 3;
private static final String CREATE_MY_CHOICES_TABLE = "create table " + MY_CHOICES + " ("
+ KEY_ROWID + " integer primary key autoincrement, "
+ PERFUME_ID + " numeric, "
+ GOT_IT + " text not null);";
private static final String CREATE_RATINGS_TABLE = "create table " + RATINGS + " ("
+ KEY_ROWID + " integer primary key autoincrement, "
+ PERFUME_ID + " numeric, "
+ RATING + " numeric);";
private static final String CREATE_CONSULTANT_TABLE = "create table " + CONSULTANT_DETAILS + " ("
+ KEY_ROWID + " integer primary key autoincrement, "
+ NAME + " text not null, "
+ WEBSITE + " text not null, "
+ PHONE + " text not null, "
+ FACEBOOK + " text not null);";
public SQLiteDatabase mDataBase;
public LocalDatabaseHelper(Context context) {
super(context, DB_NAME, null, DATABASE_VERSION);
Log.v(TAG,"LocalDataBaseHelper()");
boolean dbexist = checkdatabase();
if (dbexist) {
} else {
Log.v(TAG,"DataBaseHelper() database doesn't exist");
this.getReadableDatabase();
}
}
private boolean checkdatabase() {
boolean checkdb = false;
try {
File dbfile = new File(DB_PATH + DB_NAME);
checkdb = dbfile.exists();
} catch (SQLiteException e) {
throw new Error("Database doesn't exist");
}
return checkdb;
}
public void open() {
// Open the database
mDataBase = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null,
SQLiteDatabase.OPEN_READWRITE);
}
public Cursor getConsultantDetails() {
Log.v(TAG,"inside getConsultantDetails()");
return mDataBase.query(CONSULTANT_DETAILS, new String[] {NAME, PHONE,WEBSITE,FACEBOOK}, null, null, null, null, null);
}
public void addConsultant(String name, String phone, String website, String facebook) {
ContentValues initialValues = new ContentValues();
initialValues.put(NAME, name);
initialValues.put(PHONE, phone);
initialValues.put(WEBSITE, website);
initialValues.put(FACEBOOK, facebook);
mDataBase.insert(CONSULTANT_DETAILS, null, initialValues);
}
@Override
public synchronized void close() {
if(mDataBase != null)
mDataBase.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_CONSULTANT_TABLE);
db.execSQL(CREATE_RATINGS_TABLE);
db.execSQL(CREATE_MY_CHOICES_TABLE);
Log.v(TAG,"onCreate()");
}
public String getDBName(){
return DB_NAME;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }
}
这是我在调用getConsultantDetails()
时得到的错误06-24 12:09:07.040: E/SQLiteLog(952): (14) cannot open file at line 30174 of [00bb9c9ce4]
06-24 12:09:07.040: E/SQLiteLog(952): (14) os_unix.c:30174: (2) open(//data/data/com.cybergeniesolutions.scentsysquirrel/databases/local.db) -
06-24 12:09:07.080: E/SQLiteDatabase(952): Failed to open database 'data/data/com.cybergeniesolutions.scentsysquirrel/databases/local.db'.
06-24 12:09:07.080: E/SQLiteDatabase(952): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
06-24 12:09:07.080: E/SQLiteDatabase(952): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
06-24 12:09:07.080: E/SQLiteDatabase(952): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
06-24 12:09:07.080: E/SQLiteDatabase(952): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
06-24 12:09:07.080: E/SQLiteDatabase(952): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)