SQLite应用程序在模拟器上工作,但在手机中似乎没有数据库错误

时间:2015-07-12 13:26:23

标签: android sqlite

我有一个SQLite应用程序,我是Android新手。在模拟器中一切正常,当我安装在手机中时,我的应用程序关闭了。我在StackOverflow中搜索并用Google搜索,我找到了一些解决方案,但没有任何效果。最后我需要一些帮助。

我从资产中获取getdb的代码是:

private void copyDatabaseFromAssets() {
        // TODO Auto-generated method stub
        InputStream inputStream = null;
        OutputStream outputStream = null;
        String DataBasePath = DATABASE_PATH + DATABASE_NAME;
        try{

            inputStream = context.getAssets().open(DATABASE_NAME);
            outputStream =new FileOutputStream(DataBasePath);
            byte[] buffer = new byte[1024];
            int length;
            while((length =inputStream.read(buffer))>0){
                outputStream.write(buffer, 0, length);
            }
            outputStream.flush();
            outputStream.close();
            inputStream.close();

        }catch(IOException e){
            throw new Error("Problem copying database from resource file");
        }

}

1 个答案:

答案 0 :(得分:0)

请确保您的Android清单中有此权限

问题可能是,如果没有,请在发生错误时显示您的logcat或堆栈跟踪。

此致