我想复制一个自定义的 sqlite 数据库到 android 中
public class DataBaseHelper extends SQLiteOpenHelper { private static String TAG = "DataBaseHelper"; // Tag just for the LogCat window private static String DB_PATH = "/data/data/mypackagename/databases/";//path of our database private static String DB_NAME ="application-database";// Database name private SQLiteDatabase mDataBase; private final Context mContext; public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; this.mContext = context; } public void createDataBase() throws IOException { //If database not exists copy it from the assets boolean mDataBaseExist = checkDataBase(); if(!mDataBaseExist) { this.getReadableDatabase(); this.close(); try { //Copy the database from assests copyDataBase(); Log.e(TAG, "createDatabase database created"); } catch (IOException mIOException) { throw new Error("ErrorCopyingDataBase"); } } }
当运行到 InputStream mInput = mContext.getAssets().open(DB_NAME);
给出一个错误,程序直接跳转到
catch (IOException mIOException) { throw new Error("ErrorCopyingDataBase"); }
数据库是在 assets 文件夹中。
这个问题出在哪里呢?
繁花如伊
相关分类