I am trying to copy a database that I made with SQLite manager, in which I did:
CREATE TABLE \"android_metadata\" (\"locale\" TEXT DEFAULT \'en_US\')
The mistake was using umlauts ü,ö,ä in the database column names.
Although you can get the content by switching with the method cursor.movetonext()
so often until you moved to the right number, it was very annoying and requested a bunch of code.
I guess this should solve the problems for most of you. I guess anything but ASCII is wrong -- spaces, dots, minuses etc., cannot be used either.
You may successfully create a database and you may can see with external sqlite tools but android will always nag.
Before you start reading the consecutive values by using c.moveToNext()
, set the cursor to the initial position, that is the beginning of your database.
c.moveToFirst()
and then start reading form it.
Might solve your problem.
Another Scenario when this can happen:
You are deleting rows from the cursor while the cursor is still in use.
E.g pseudo-coden where it could happen:
while(cursor.moveToNext()){
readCursor(cursor);
deleteRowFromCursor(cursor);
}
Solution:
Keep list of rows you want to delete; build a batch delete sql statement; execute the statment out side of the while loop ( when you are done with using the cursor anymore or after you close it).
while(cursor.moveToNext()){
readCursor(cursor);
queueRowForDelete(cursor);
}
deleteQueuedRows(queuedRowsList);
if you see
failed to read row 0,column -1
It means you are trying to read from a column which doesn't exist.
If it cannot find the column name that you specify, Cursor.getColumnIndex()
returns -1
and hence, is invalid.
There are two reasons for this:
Note: the name of the column is CASE SENSITIVE when using getColumnIndex()
In your scenario:
c.getString(c.getColumnIndex(CNAME));
Check that the CNAME variable is spelt correctly, and that a column of that name exists.
String CNAME=" ques"
Should that extra leading white space be there for example..