android – 数据库没有从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();

        }

我是否应该做其他事情将该数据库复制到设备?

谢谢..

解决方法:

得到了答案……

上一篇:android – 如何使用ActionScript 3访问APK文件中的资源? (Adobe AIR)


下一篇:implements KeyListener但关键监听器监听少