Android caused By:java.lang.IllegalArgumentException:column ' _id ' does not exist

Source: Internet
Author: User

Cause of error: When querying the entire SQLite database, there is no query to the "_id" column.

The original code is: Msqlitedatabase.query (table_name, new string[] {_title}, NULL, NULL, NULL, NULL, NULL);

The modified code is: msqlitedatabase.query (table_name, NULL, NULL, NULL, NULL, NULL, NULL);

Here the new string[] {myevent._title} is a query condition, the contents of the array is to query the table column name, here is the limit you want to query the column. A parameter value of NULL indicates that all columns are queried (containing the column "_id"). Such changes are also possible: msqlitedatabase.query (table_name, new string[] {_id, _title}, NULL, NULL, NULL, NULL, NULL); The goal is to have the "_id" column in the results of your query.

In addition, about the "_id" column in the SQLite database, it must be in the SQLite database, and the column name must also be "_id" general primary key. The "_id" column is also required when the following code is displayed in a ListView.

public void Updataadapter () {
        if (mcursor! = NULL &&!) Mcursor.isclosed ())
            mcursor.close ();
        
        mcursor = m_ Mydatabaseadapter.fetchalldata ();
        mcursor.movetofirst ();
        
        if (mcursor! = null && Mcursor.getcount () > 0) {
            listadapter adapter = new Simplecursoradapter (this, Android. R.layout.simple_list_item_1, Mcursor, new string[] {_title}, new int[] {Android. R.ID.TEXT1});
            listview.setadapter (adapter);
        }
 }

The simplecursoradapter shown here will be displayed according to "_id", "_id" is a must.

Android caused By:java.lang.IllegalArgumentException:column ' _id ' does not exist

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.