Java. lang. IllegalArgumentException: column & #39; _ id & #39; does not exist, doesnotexist

Source: Internet
Author: User

Java. lang. IllegalArgumentException: column '_ id' does not exist, doesnotexist

When you use SimpleCursorAdapter to display SQLite data to ListView, the error java. lang. IllegalArgumentException: column '_ id' does not exist is displayed, indicating that the field "_ id" does not exist.

Let's take a look at the inheritance relationship of SimpleCursorAdapter, and you will know why:


We can see that SimpleCursorAdapter inherits ResourseCursorAdapter, while ResourseCursorAdapter inherits CursorAdapter. Now let's take a look at the description of CursorAdapter:

Adapter that exposes data fromCursorToListViewWidget. The Cursor must include a column named "_ id" or this class will not work.

The adapter displays data from the cursor to the ListView view control. The cursor must contain a column named "_ id" or the class will not work.

At this time, we can understand that when we query the SQLite database, the query field does not contain "_ id", so the cursor does not have the "_ id" field. In SimpleCursorAdapter (Context context, int layout, Cursor c, String [] from, int [] to), a column corresponding to "_ id" must also exist to succeed.

So the solution is: the query field must contain "_ id", and the from in the constructor of SimpleCursorAdapter must also have "_ id" corresponding to the query field ", you can solve the problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.