【发布时间】:2012-05-30 03:08:57
【问题描述】:
我是安卓开发新手。现在我正在尝试使用 sqlite db。我使用 sqlite manager 创建了一个数据库 sqlite 文件。 我尝试了以下代码,它在模拟器中运行良好,但如果我在设备中发布应用程序崩溃,即显示一条警告消息应用程序 CheckMobileForDatabase 已意外停止,我的 sdk 版本是 2.2(8)
private void StoreDatabase() {
File DbFile=new File("data/data/com.sqldemo/databases/idua1");
if(DbFile.exists())
{
System.out.println("file already exist ,No need to Create");
}
else
{
try
{
DbFile.createNewFile();
System.out.println("File Created successfully");
InputStream is = this.getAssets().open("idua1.sqlite");
FileOutputStream fos = new FileOutputStream(DbFile);
byte[] buffer = new byte[1024];
int length=0;
while ((length = is.read(buffer))>0)
{
fos.write(buffer, 0, length);
}
System.out.println("File succesfully placed on sdcard");
//Close the streams
fos.flush();
fos.close();
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
【问题讨论】:
-
请发布显示错误的logcat。
-
以上代码在模拟器中工作正常,但我发布该项目它在模拟器中工作正常,应用程序崩溃,它显示警告消息应用程序 CheckMobileForDatabase 已意外停止。请解决此问题
-
所以在手机插入的情况下运行它,然后在它崩溃时抓住 logcat 并发布它。我们不能做任何事情而不知道它失败的为什么,因为您发布的代码中没有任何明显的内容。
-
任何其他更改我的代码
标签: java android database sqlite import