Reputation: 343
I'm trying to use a SQLite db in my android app. It used to work ( and I swear I didn't change anything ), and clearly something changed, as my code now does not return anything upon querying the db. As I stepped through the code itself, I noticed that as soon as my DBHelper called this.getReadableDatabase()
the database had a mStackTrace
of DatabaseObjectNotClosedException, even though it is the first time I have ever opened the db in the app itself. Strangely enough, this error is never actually thrown, and it may not even be my problem, but I think it is a good place to start.
Code:
{snip}
I'm not 100% on what exactly is going on here. The class is supposed to copy the database from res/assets to the local data folder, and it appears to work, but the database either is incorrect, or ends up being pointed to the wrong thing, because no rows are ever returned. Thoughts?
Edit: Additional update; I took a look through the data/ dir where I am storing files, and I have found two separate databases, one in files/
and one in databases/
. files/
has the correct DB with all data intact, and databases/
is just a blank database setup for android. My code is supposed to call the database in files/
, but perhaps it is not?
Edit: Solved. I found the problem, and it had nothing to do with my DBhelper. Apparently my cohort on the project edited a field that he shouldn't have for testing, and forgot to change it back. Turned out that the SQL call I was making was faulty. Thanks for the help!
Upvotes: 0
Views: 395
Reputation: 343
Edit: Solved. I found the problem, and it had nothing to do with my DBhelper. Apparently my cohort on the project edited a field that he shouldn't have for testing, and forgot to change it back. Turned out that the SQL call I was making was faulty. Thanks for the help!
Upvotes: 0
Reputation: 83303
Make sure you are only ever working with one instance of SQLiteOpenHelper
, as described in this blog post. I'm betting the problem is that you have created multiple instances of the class accidentally and have forgotten to close one of them. You could also do what Sam suggests and be very careful to close the SQLiteOpenHelper
instances that you create. However, in my opinion it is much cleaner to work with the same SQLiteOpenHelper
across the entire application's lifecycle.
Upvotes: 1