Reputation: 3210
I do not see any methods in SQLiteDatabase
class and SQLiteDatabaseOpener
Therefore I got this error:
AndroidRuntime(806): Caused by: java.lang.IllegalStateException: attempt to acquire a reference on a close SQLiteClosable
What would be a good way of designing it so that I can use the database throughout say a certain class?
Thanks!
Upvotes: 1
Views: 1727
Reputation: 3210
The answer is right here Exception: attempt to acquire a reference on a close SQLiteClosable
This one drove me insane for the longest time. The solution I have found is fairly simple: don't keep references to SQLiteDatabase objects. Instead, use a SQLiteOpenHelper and call getWritableDatabase() every time you need one. From the docs:
public synchronized SQLiteDatabase getWritableDatabase()
Create and/or open a database that will be used for reading and writing. Once opened successfully, the database is cached, so you can call this method every time you need to write to the database.
The answer was right there the whole time.
Upvotes: 2