Android開発は初めてです。今、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();
}
}
}