我的文件assets
夹中有一个 .db 文件。我已经将它复制到data/data/<packagename>/databases/
模拟器中的文件夹并且它工作正常..
但是当我在设备上运行它时,它会强制关闭。它正在显示
SQLite exception: no such table: tbl_user
这是我的代码..
public class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper() {
super(dataContext, DATABASE_NAME, null, 1);
DB_PATH = "/data/data/"
+ dataContext.getApplicationContext().getPackageName()
+ "/databases/";
Log.d("PATH", DB_PATH);
boolean dbExist = checkDataBase();
if (!dbExist) {
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
Log.d("Error", e.toString());
}
}
}
private void copyDataBase() throws IOException {
// TODO Auto-generated method stub
InputStream inFile = dataContext.getAssets().open(DATABASE_NAME);
String outFileName = DB_PATH + DATABASE_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = inFile.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
// Close the streams
myOutput.flush();
myOutput.close();
inFile.close();
}
private boolean checkDataBase() {
// TODO Auto-generated method stub
File dbFile = new File(DB_PATH + DATABASE_NAME);
return dbFile.exists();
}
我应该做其他事情来将该数据库复制到设备吗???
谢谢..