Friday, 6 September 2013

How to Prevent "sqlite_config failed error_code = 21. THIS SHOULD NEVER occur" errors

How to Prevent "sqlite_config failed error_code = 21. THIS SHOULD NEVER
occur" errors

This unhelpful error message has been driving me crazy recently; it does
not occur within the android emulator, only when running on my (android
2.3.6) device via USB debugging, launched from Eclipse.
No exceptions are actually being thrown, and as far as I can tell none of
my database queries are actually failing (everything seems to be working
normally), yet I'm receiving at least one of these error for every query
that I run.
As far as I can tell I'm doing everything right:
I'm using one SQLiteOpenHelper instance created as a singleton
(synchronised static method retrieves a single instance using the
application's context).
I only call getWritableDatabase() when I need to run an update, insert
etc., the rest of the time I use getReadableDatabase().
All actions that involve a writable database are also wrapped in
transactions with a try/catch/finally block to ensure endTransaction() is
called.
All other queries are wrapped in a try/catch block to catch any possible
SQLException responses, which are logged as appropriate.
I am calling close() on all SQLiteDatabase and Cursor objects that I'm using.
Most of these are things that used to throw background errors in the
emulator until I corrected them, and when I run my app in the emulator I
see no database errors of any kind any more. Yet running on my device I
get the unhelpful "THIS SHOULD NEVER occur" errors seemingly for every
single query I run, with no apparent ill effects.
Of course I'm just ignoring these for the time being, but I can't think of
any other possible causes. My SQL statements are all valid, and most of my
code is based on the official android tutorials such as the one here.
Can anyone identify why I would be getting these errors? What other
possible causes are there?

No comments:

Post a Comment