我有一個預製的SQLite數據庫,我通過AsyncTask從網上下載。它下載文件並將其存儲在SD卡上的/ data/databases /我已檢查數據庫文件,並且它已成功下載並具有所有適當的表和數據,但每次嘗試打開數據庫並顯示存儲的數據時,我都會得到以下打開下載SQLite數據庫
03-19 18:43:10.204: E/AndroidRuntime(3057): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ondrovic.downloader/com.ondrovic.downloader.Main}: android.database.sqlite.SQLiteException: no such table: beers: , while compiling: SELECT * FROM beers ORDER BY _id
這是沒有意義的,因爲該表是有
也許我databasehelper類是錯誤的或我打電話是錯誤的。
這裏是我的database.java
package com.ondrovic.downloader;
import java.io.File;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
public class Database extends SQLiteOpenHelper{
//File rDIR = Environment.getExternalStorageDirectory();
private static String DBPATH = "/data/databases/BOOMBOZZ/";
private static String DBNAME = "boombozz.db";
private static int DBVER = 1;
private SQLiteDatabase db;
private final Context dbContext;
public Database(Context context) {
super(context, DBNAME, null, DBVER);
this.dbContext = context;
}
public void open() {
String myPath = DBPATH + DBNAME;
db = SQLiteDatabase.openDatabase(Environment.getExternalStorageDirectory() + myPath, null, SQLiteDatabase.OPEN_READWRITE);
}
public synchronized void close() {
db.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
而且這裏是我在我的主類
db = (new Database(this)).getWritableDatabase();
任何建議,稱這是?
感謝
http://stackoverflow.com/questions/9109438/using-already-created-database-with-android/9109728#9109728 – 2012-04-06 05:48:15