Android SQLite数据库赢得';在测试过程中,不要被推到手机前

Android SQLite数据库赢得';在测试过程中,不要被推到手机前,android,sqlite,Android,Sqlite,我的sqlite数据库在我的资产文件夹中。当我在模拟器或我的设备上测试我的应用程序时,db名为foo.db,它总是说不存在db,创建空白db。我的数据库加载了数据,我想把它推到手机或模拟器上进行测试。为什么这不起作用 下面是我的应用程序中检查数据库是否存在的部分。。。但它从未找到它。我已经在调试模式下运行了它,DB_路径和DB_名称都有正确的值,但每次都会创建一个空数据库 我忽略了什么 /** * Called when the activity is first created. */ @

我的sqlite数据库在我的资产文件夹中。当我在模拟器或我的设备上测试我的应用程序时,db名为foo.db,它总是说不存在db,创建空白db。我的数据库加载了数据,我想把它推到手机或模拟器上进行测试。为什么这不起作用

下面是我的应用程序中检查数据库是否存在的部分。。。但它从未找到它。我已经在调试模式下运行了它,DB_路径和DB_名称都有正确的值,但每次都会创建一个空数据库

我忽略了什么

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listpage);
    this.myDbHelper = new DataBaseHelper(this);
    try {
        myDbHelper.createDataBase();
    } catch (IOException ioe) {
        throw new Error("Unable to create database");
    }
    try {
        myDbHelper.openDataBase();
    } catch (SQLException sqle) {
        throw sqle;
    }
}

/**
 * Creates a empty database on the system and rewrites it with your own database.
 */
public void createDataBase() throws IOException {
    boolean dbExist = checkDataBase();
    if (dbExist) {
        //do nothing - database already exist
        System.out.println("DB alrady exists  comment this out before your deply");
    } else {
        System.out.println("an empty DB is beng created  comment this out before your deply");
        //By calling this method an empty database will be created into the default system path
        //of your application so we are gonna be able to overwrite that database with our database.
        this.getReadableDatabase();
        try {
            copyDataBase();
        } catch (IOException e) {
            throw new Error("Error copying database");
        }
    }
}


/**
 * Check if the database already exist to avoid re-copying the file each time you open the
 * application.
 *
 * @return true if it exists, false if it doesn't
 */
private boolean checkDataBase() {
    SQLiteDatabase checkDB = null;
    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
        //database does't exist yet.
    }

    if (checkDB != null) {
        checkDB.close();
    }
    return checkDB != null ? true : false;
}

你如何访问这个?通过“Assets\”或通过执行私有静态字符串DB_PATH=Environment.getExternalStorageDirectory().toString()+“/data/my_package_name/databases/”;Context.getFilesDir().getPath()+Context.getApplicationContext().getPackageName()+“/databases/”;这是路吗?