You can also get this exception if you try to retrieve or insert a NULL control character like "\u0000" into an SQLite database, using a text query:
SELECT * FROM my_table WHERE text =
"Here is a NULL control character \u0000 in the text";
Although there is no easy way for a keyboard to type a control character, it's still a valid character in Java String, and it will cause an exception when the String is sent to the Android SQLite database:
android.database.sqlite.SQLiteException: unrecognized token (code 1):
"'Here is a NULL control character ":
, while compling: SELECT * FROM my_table WHERE text = '...';
at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1763)
Because it's an invisible character and not easily spotted, you can use a Hex display of the string, to see all the characters. For example, use BBEdit's 'Hex dump front document' as UTF-16LE (Little-Endian).
To avoid this crash, you have to remove this NULL character, using String.replace()
. See examples here: