Neil Walker
Neil Walker

Reputation: 6868

Android sqlite close never called exception but it was definitely closed

I'm getting errors in my unit tests in android:

01-23 00:13:45.430: E/Database(9907): close() was never explicitly called on database '/data/data/com.chucklepie.androidtest/databases/androidtest.db' 

However, the line it is falling over is below in the getReadableDatabase. How can it be saying it wasn't closed? In fact in all the tests I'm doing with various connections and database states it always falls over after trying to close a database previously opened with a getWriteableDatabase followed by opening it readable.

if (!db.isReadOnly()) {
    db.close();
    db = dbHelper.getReadableDatabase();
}

I know you aren't always guaranteed a readable database if a writeable one is pooled but it shouldn't be erroring on me should it?

dbHelper is the same object, btw every time.

Upvotes: 1

Views: 57

Answers (1)

laalto
laalto

Reputation: 152927

This isn't really an error but just a noisy log message logged with the error log level in SQLiteDatabase finalizer. It contains an exception stacktrace, yes, but it's there only to record where the database was opened. Source

It might be possible that you still have some database-related object not closed (cursors, database instances etc.).

You can also safely ignore the message.

By the way, this message was removed in 4.1 Jelly Bean.

Upvotes: 1

Related Questions