我是android开发新手。现在即时尝试使用sqlite数据库。我使用sqlite管理器创建了一个数据库sqlite文件。 我曾尝试下面的代码,它工作在模拟器罚款,但如果我在装置了发布应用程序崩溃,即,它显示一条警告消息CheckMobileForDatabase意外停止的应用程序,我的SDK版本是2.2(8)Android中导入数据库的问题
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的表现错误。 – Barak
上面的代码在模拟器中工作正常,但我释放该项目它在模拟器中正常工作,应用程序崩溃,它显示一条警报消息应用程序CheckMobileForDatabase已意外停止。解决此问题 – NAZIK
因此,使用插入的手机运行它,然后抓住logcat,当它崩溃并发布。没有看到*为什么*它失败了,我们什么也做不了,因为您发布的代码中没有任何明显的内容。 – Barak