将sqlite数据库从android项目的资产文件夹复制到首选位置时出错

时间:2013-03-18 11:19:18

标签: android android-sqlite

当我尝试从资产文件夹中复制数据库时,我收到以下错误。

Error:  A fatal error has been detected by the Java Runtime Environment:

#  Internal Error (classFileParser.cpp:3470), pid=6696, tid=4792
#  Error: ShouldNotReachHere()
#
# JRE version: 7.0-b147
# Java VM: Java HotSpot(TM) 64-Bit Server VM (21.0-b17 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# hs_err_pid6696.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#

代码链接: Sqlite database not copied from asset folder Android

编辑:

AssetManager am = getApplicationContext().getAssets();
    OutputStream os = new    FileOutputStream("/data/data/"+getPackageName+"/databases/dbname.sqlite");
    byte[] b = new byte[100];
    int r;
    InputStream is = am.open("dbname.sqlite");
    while ((r = is.read(b)) != -1) {
         os.write(b, 0, r);
   }
   is.close();
   os.close();
}

我正在尝试运行此代码.. 此代码从android中的asset文件夹复制数据库。 当我运行此代码..它显示上述错误

1 个答案:

答案 0 :(得分:0)

上述错误是由于应用程序作为普通的Java应用程序而不是Android应用程序运行而引起的。

只需将eclipse中项目的运行配置更改为android应用程序即可解决上述问题。感谢