SQLite抛出错误“未关闭游标及数据库对象”特殊原因一例
Html代码Android 2.3.3
Eclipse Version: 3.7.0
LogCat
Android 2.3.3
Eclipse Version: 3.7.0
LogCat LogCat 报错信息:
Java代码
02-13 13:29:32.830: WARN/ActivityManager(62): Launch timeout has expired, giving up wake lock!
02-13 13:29:33.381: DEBUG/dalvikvm(17173): GC_CONCURRENT freed 771K, 57% free 2908K/6727K, external 2013K/2137K, paused 7ms+5ms
02-13 13:29:33.630: DEBUG/dalvikvm(17173): GC_FOR_MALLOC freed 867K, 58% free 2836K/6727K, external 2013K/2137K, paused 178ms
02-13 13:29:33.859: ERROR/Database(17173): close() was never explicitly called on database '/data/data/com.tmall.nokia/databases/taobaoNokia.db'
02-13 13:29:33.859: ERROR/Database(17173): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
02-13 13:29:33.859: ERROR/Database(17173): at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1847)
02-13 13:29:33.859: ERROR/Database(17173): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
02-13 13:29:33.859: ERROR/Database(17173): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
02-13 13:29:33.859: ERROR/Database(17173): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
02-13 13:29:33.859: ERROR/Database(17173): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:544)
02-13 13:29:33.859: ERROR/Database(17173): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
02-13 13:29:33.859: ERROR/Database(17173): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
02-13 13:29:33.859: ERROR/Database(17173): at com.tmall.nokia.db.RecordDBHelper.query(RecordDBHelper.java:49)
02-13 13:29:33.859: ERROR/Database(17173): at com.tmall.nokia.manage.RecordDBopt.get(RecordDBopt.java:78)
02-13 13:29:33.859: ERROR/Database(17173): at com.tmall.nokia.manage.RecordMessage.sendMseeage(RecordMessage.java:111)
02-13 13:29:33.859: ERROR/Database(17173): at com.tmall.nokia.manage.RecordMessage.sendMseeage(RecordMessage.java:87)
02-13 13:29:33.859: ERROR/Database(17173): at com.tmall.nokia.Report.run(Report.java:49)
02-13 13:29:33.859: ERROR/Database(17173): at java.lang.Thread.run(Thread.java:1019)
02-13 13:29:33.830: WARN/ActivityManager(62): Launch timeout has expired, giving up wake lock!
02-13 13:29:34.381: DEBUG/dalvikvm(17173): GC_CONCURRENT freed 771K, 57% free 2908K/6727K, external 2013K/2137K, paused 7ms+5ms
02-13 13:29:34.630: DEBUG/dalvikvm(17173): GC_FOR_MALLOC freed 867K, 58% free 2836K/6727K, external 2013K/2137K, paused 178ms
02-13 13:29:32.830: WARN/ActivityManager(62): Launch timeout has expired, giving up wake lock!
02-13 13:29:33.381: DEBUG/dalvikvm(17173): GC_CONCURRENT freed 771K, 57% free 2908K/6727K, external 2013K/2137K, paused 7ms+5ms
02-13 13:29:33.630: DEBUG/dalvikvm(17173): GC_FOR_MALLOC freed 867K, 58% free 2836K/6727K, external 2013K/2137K, paused 178ms
02-13 13:29:33.859: ERROR/Database(17173): close() was never explicitly called on database '/data/data/com.tmall.nokia/databases/taobaoNokia.db'
02-13 13:29:33.859: ERROR/Database(17173): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
02-13 13:29:33.859: ERROR/Database(17173): at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1847)
02-13 13:29:33.859: ERROR/Database(17173): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
02-13 13:29:33.859: ERROR/Database(17173): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
02-13 13:29:33.859: ERROR/Database(17173): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
02-13 13:29:33.859: ERROR/Database(17173): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:544)
02-13 13:29:33.859: ERROR/Database(17173): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
02-13 13:29:33.859: ERROR/Database(17173): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
02-13 13:29:33.859: ERROR/Database(17173): at com.tmall.nokia.db.RecordDBHelper.query(RecordDBHelper.java:49)
02-13 13:29:33.859: ERROR/Database(17173): at com.tmall.nokia.manage.RecordDBopt.get(RecordDBopt.java:78)
02-13 13:29:33.859: ERROR/Database(17173): at com.tmall.nokia.manage.RecordMessage.sendMseeage(RecordMessage.java:111)
02-13 13:29:33.859: ERROR/Database(17173): at com.tmall.nokia.manage.RecordMessage.sendMseeage(RecordMessage.java:87)
02-13 13:29:33.859: ERROR/Database(17173): at com.tmall.nokia.Report.run(Report.java:49)
02-13 13:29:33.859: ERROR/Database(17173): at java.lang.Thread.run(Thread.java:1019)
02-13 13:29:33.830: WARN/ActivityManager(62): Launch timeout has expired, giving up wake lock!
02-13 13:29:34.381: DEBUG/dalvikvm(17173): GC_CONCURRENT freed 771K, 57% free 2908K/6727K, external 2013K/2137K, paused 7ms+5ms
02-13 13:29:34.630: DEBUG/dalvikvm(17173): GC_FOR_MALLOC freed 867K, 58% free 2836K/6727K, external 2013K/2137K, paused 178ms
发生错误原因分析:
主要错误:
Java代码
02-13 13:29:33.859: ERROR/Database(17173): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
02-13 13:29:33.859: ERROR/Database(17173): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
出错处代码
Java代码
SQLiteDatabase db = getWritableDatabase();
SQLiteDatabase db = getWritableDatabase();
意思是指在此处打开数据库操作之前,应用程序没有关闭游标或数据库对象。
在应用中,对数据库操作完成后,应该对游标及数据库进行关闭操作
Java代码
if (!cur.isClosed()) {
cur.close();
}
db.close();
if (!cur.isClosed()) {
cur.close();
}
db.close();
检查操作数据库的相关源代码,确认在退出前关闭了游标及数据库对象。
那还抛出未关闭的错误是怎么回事呢?继续检查发现,抛出此错误之前,在操作数据库过程中还抛出了另外的一个错误。
原来在抛出第一个错误以后,关闭操作未执行,导致再次操作数据库时抛出“应用程序没有关闭游标或数据库对象”的错误。
解决办法:
- 更多SQLite疑问解答:
- 数据库sqlite3 里:用函数sqlite3_get_table来获取数据是否 可以 排序么(order by cTime asc)
- 开始学sqlite,在下载了个sqlite3_exe,和一个sqlite admin数据库,我现在疑问的是,可以通过sqlite3.exe
- 关于Sqlite使用Group by以后的排序问题。
- sqlite做网络数据库怎么样
- sqlite支持动态sQL,能不能给个对表名进行拼接的,可以运行通的过的代码范例啊,大侠们
- 用SQLite expert创建的数据库,如何导入到android中
- sqlite3 开始建立数据库时,没有设定主键。怎么去修改
- Android中用SQLite数据库是出现的错误,帮忙解决一下:
- android 应用程序开发用到数据库 ,是否需要使用SQLite Manager
- sqlite查询条件参数为空怎么办
- Android sqlite通过字符串为条件执行删除某一记录的问题
- android 程序碰到问题,很简单的一个程序,从sqlite数据库里面查找数据,点击按钮后获得相应数据
- sqlite数据库中插入数据时出现database is locked!什么原因?我没有设置密码.
- ios移动开发、QT应用开发、ZigBee协议栈、SQlite数据库支持,这些都可以描述成我应用到的技术吗?
- sqlite和mysql有关系吗? 能代替mysql运行织梦程序吗?