SQLite数据库,应用程序没有关闭游标或数据库对象

前端之家收集整理的这篇文章主要介绍了SQLite数据库,应用程序没有关闭游标或数据库对象前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Android 2.3.3           
Eclipse Version: 3.7.0           
LogCat  


LogCat 报错信息:

02-13 11:58:13.759: ERROR/Database(432): close() was never explicitly called on database '/data/data/com.taobao.htc/databases/taobaoHtc.db' 
02-13 11:58:13.759: ERROR/Database(432): android.database.sqlite.DatabaSEObjectNotClosedException: Application did not close the cursor or database object that was opened here
02-13 11:58:13.759: ERROR/Database(432): at android.database.sqlite.sqliteDatabase.(sqliteDatabase.java:1847)
02-13 11:58:13.759: ERROR/Database(432): at android.database.sqlite.sqliteDatabase.openDatabase(sqliteDatabase.java:820)
02-13 11:58:13.759: ERROR/Database(432): at android.database.sqlite.sqliteDatabase.openOrCreateDatabase(sqliteDatabase.java:854)
02-13 11:58:13.759: ERROR/Database(432): at android.database.sqlite.sqliteDatabase.openOrCreateDatabase(sqliteDatabase.java:847)
02-13 11:58:13.759: ERROR/Database(432): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:544)
02-13 11:58:13.759: ERROR/Database(432): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
02-13 11:58:13.759: ERROR/Database(432): at android.database.sqlite.sqliteOpenHelper.getWritableDatabase(sqliteOpenHelper.java:118)
02-13 11:58:13.759: ERROR/Database(432): at com.taobao.htc.db.RecordDBHelper.query(RecordDBHelper.java:49)
02-13 11:58:13.759: ERROR/Database(432): at com.taobao.htc.manage.RecordDBopt.get(RecordDBopt.java:78)
02-13 11:58:13.759: ERROR/Database(432): at com.taobao.htc.manage.RecordMessage.sendMseeage(RecordMessage.java:111)
02-13 11:58:13.759: ERROR/Database(432): at com.taobao.htc.manage.RecordMessage.sendMseeage(RecordMessage.java:87)
02-13 11:58:13.759: ERROR/Database(432): at com.taobao.htc.Report.run(Report.java:49)
02-13 11:58:13.759: ERROR/Database(432): at java.lang.Thread.run(Thread.java:1019)
02-13 11:58:13.830: WARN/ActivityManager(62): Launch timeout has expired,giving up wake lock!
02-13 11:58:14.381: DEBUG/dalvikvm(432): GC_CONCURRENT freed 771K,57% free 2908K/6727K,external 2013K/2137K,paused 7ms+5ms
02-13 11:58:14.630: DEBUG/dalvikvm(432): GC_FOR_MALLOC freed 867K,58% free 2836K/6727K,paused 178ms


发生错误原因分析:

主要错误

02-13 11:58:13.759: ERROR/Database(432): android.database.sqlite.DatabaSEObjectNotClosedException: Application did not close the cursor or database object that was opened here


出错处代码

		sqliteDatabase db = getWritableDatabase();

意思是指在此处打开数据库操作之前,应用程序没有关闭游标或数据库对象。

在应用中,对数据库操作完成后,应该对游标及数据库进行关闭操作

		if (!cur.isClosed()) {
			cur.close();
		}
		db.close();


解决办法:

检查操作数据库的相关源代码增加关闭“cursor or database object”的代码

PS。

原文链接:https://www.f2er.com/sqlite/202244.html

猜你在找的Sqlite相关文章