Search code examples
androidsqlitecursorsimplecursoradapter

Simple Cursor Adapter Throw Exception illegal Argument exception?


My Cursor

    Cursor c= db.query(DBHelper.EXAM_DATA,new String [] {DBHelper.EXAM,DBHelper.FILE}, null,null, null, null, null);

Loop for the Cursor

c.moveToFirst();
    do
    {
        name = c.getString(0);
        file = c.getString(1);
        Toast.makeText(this, name + "   "+file  ,Toast.LENGTH_LONG).show();
        adapter = new SimpleCursorAdapter(this, R.layout.row_reasoning, c, new String [] {file}, new int [] {R.id.txtList});
        LvReasoning.setAdapter(adapter);
    }while(c.moveToNext());

Logcat Showing This Error

01-20 16:33:55.154: E/AndroidRuntime(2426): FATAL EXCEPTION: main
01-20 16:33:55.154: E/AndroidRuntime(2426): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androidhive.xmlparsing/com.androidhive.xmlparsing.ListReasoning}: java.lang.IllegalArgumentException: column '_id' does not exist

My Table have _id Column but I do not know how to solve this error


Solution

  • c.moveToFirst();
        do
        {
            name = c.getString(0);
            file = c.getString(1);
            Toast.makeText(this, name + "   "+file  ,Toast.LENGTH_LONG).show();
            adapter = new SimpleCursorAdapter(this, R.layout.row_reasoning, c, new String [] {DBHelper.FILE}, new int [] {R.id.txtList});
    
        }while(c.moveToNext());
        LvReasoning.setAdapter(adapter);
    

    I used this and This is Working. I have passed DBHelper table field name and its Work Fine.. But I really dont know Why that code not worked...