jersam515
jersam515

Reputation: 657

Why is my ListAdapter for android not working?

I am trying to get info from a database to a listadabter. Here is my code for getting the information to the layout:

    Cursor c = mnDbHelper.fetchAllNotes();
    startManagingCursor(c);
   String[] columns = new String[] {EquationsDbAdapter.KEY_VALUE};
   int to[] = new int[] {android.R.id.text1};
   SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1 ,c , columns , to);
   setListAdapter(adapter);

My error is given by LogCat as :java.lang.IllegalArgumentException: column '_id' does not exist I have seen some other questions and tutorials and none of those seem to solve my problem. I don't even have a column in my database for _id.

Upvotes: 1

Views: 158

Answers (1)

hooked82
hooked82

Reputation: 6376

This is because SimpleCursorAdapter needs a field returned called "_id", though it doesn't have to be an actual name of a column in your table, but could be an alias. There's a few threads here on SO talking about this, such as:

Android: column '_id' does not exist

Android column '_id' does not exist?

Upvotes: 1

Related Questions