This is the error i’m getting when i try to run my application
Illegal argument exception in android : Column _id doesn’t exist
public static final String OBJ_ID="_id";
and the creation of database is as follows:
private static final String CREATE_TAB1= "create table " + TABLE_1 + " (" + OBJ_ID + " integer primary key
autoincrement, " + OBJ_NAME + " text not null, " + DESC1 + " text not null, " + DESC2 + " text not null);";
Trying to retrieve the data by using the following function in databasehandler:
public Cursor getAllTable1() {
return db.query(TABLE_1,
new String[] { OBJ_NAME },
null, null, null, null, null);
}
This is the function where i communicate with databse
public class List_View extends ListActivity {
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.displayitems);
Databasehelp db = new Databasehelp(this);
db.open();
Cursor cursor = db.getAllTable1();
startManagingCursor(cursor);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.list_example_entry, cursor,
new String[] {"name"},
new int[] {R.id.name_entry });
setListAdapter(adapter);
}
}
Although my database schema consist of column named _id. I changed this to even _ID but didn’t seem to work . Can anyone pls help me in resolving this?
You must select the column
_idwhen binding a Cursor to ListView (Spinner, etc).So add the
_idcolumn like this: