我一次又一次地收到错误,当我回到previouse页面或启动页面时应用程序崩溃。在使用任何查询之前我初始化这个
dbhelper = new MyDbHelper(this);
dbhelper.onOpen(db);
如果我对db.close
的代码行发表评论,或者甚至在游标关闭后使用db.close
,则会反复出现错误。有人告诉我如何处理数据库。为什么会出现此错误。
谢谢你的支持
这是我的代码
public void getDoenLoaddata() {
SQLiteDatabase db = dbhelper.getWritableDatabase();
Cursor cursor = db.rawQuery("select * from ActivityObjectList", null);
if (cursor.moveToFirst()) {
do {
imageName = cursor.getString(cursor.getColumnIndex("imageaudioPath"));
String strDownLoadStatus = cursor.getString(cursor.getColumnIndex("DownLoad_Status"));
if (strDownLoadStatus.equalsIgnoreCase("0")) {
if (imageName.endsWith(mp3_Pattern))
{
str_DownLoadUrl = namespace + "/DownloadFile/FilePathMobile/ATTACHMENT/FileName/" + imageName;
DownLoadAudioFile(str_DownLoadUrl, imageName);
strDownLoadStatus = "1";
dbhelper.update_DownLoadStatus(imageName, strDownLoadStatus);
}
if (imageName.endsWith(png_Pattern) || imageName.endsWith(jpg_pattern) || imageName.endsWith(bmp_pattern) || imageName.endsWith(gif_pattern) || imageName.endsWith(jpeg_pattern)) {
str_DownLoadUrl = namespace + "/DownloadFile/FilePathMobile/ATTACHMENT/FileName/" + imageName;
download_PngFile(str_DownLoadUrl, imageName);
strDownLoadStatus = "1";
dbhelper.update_DownLoadStatus(imageName, strDownLoadStatus);
}
}
}
while (cursor.moveToNext());
}
cursor.close();
//db.close();
}