failed to read row 0,column -1

后端 未结 4 1721
天命终不由人
天命终不由人 2021-02-18 15:53

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\')


        
相关标签:
4条回答
  • 2021-02-18 16:13

    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.

    0 讨论(0)
  • 2021-02-18 16:16

    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.

    0 讨论(0)
  • 2021-02-18 16:21

    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);
    
    0 讨论(0)
  • 2021-02-18 16:29

    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:

    1. The column does not exist.
    2. The name of the column is incorrect. (so does not exist).

    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..

    0 讨论(0)
提交回复
热议问题