Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9112415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:43:48+00:00 2026-06-17T03:43:48+00:00

Hi am trying to create a android app with a sql database and i

  • 0

Hi am trying to create a android app with a sql database and i want to list my results in a listview but cant seem to get it to work please help I have this so far and am getting the error

java.lang.IllegalArgumentException: column ‘_id’ does not exist

SimpleCursorAdapter adp;

    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         db.open();


         // from array: keeps the names of the Cursor columns.
         String[] from = {"CURSOR_FIELD1","CURSOR_FIELD2"};
         // to array: keeps the ids of the fields in your list item layout
         int[] to = {R.id.itemLayoutfield1, R.id.itemLayoutfield2};
         // sets the basic layout of the ListActivity (the layout must contain a ListView element with the id called 'list').
         setContentView(R.layout.view_data_layout);

         // gets de cursor with the rows        
         c = db.getAllCourses(); 

         adp = new SimpleCursorAdapter(this, R.layout.row, c, from, to);             
         setListAdapter(adp);

        ListView listView = getListView();
        listView.setTextFilterEnabled(true);


        listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // When clicked, show a toast with the TextView text
                Toast.makeText(getApplicationContext(),
                ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); 

                displayAllCourses(c);

                db.close();


            }               

        });

and my dbadapter i have

public Cursor getAllCourses() {

    return db.query(DATABASE_TABLE, new String[] { ID, Time_Amount,
            Seed_Acre, MM_Settings, Acre_amount, Speed_Type, Acre_String, Seed_Type,  Hill_Name }, null, null,
            null, null, null, null);
}

public Cursor getCourse(long rowId) throws SQLException {

    Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] { ID,
            Time_Amount, Seed_Acre, MM_Settings, Acre_amount, Speed_Type, Acre_String, Seed_Type, Hill_Name },
            ID + "=" + rowId, null, null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:43:49+00:00Added an answer on June 17, 2026 at 3:43 am

    Your ‘hill‘ String array just contains one single item (which is not even the first row of the table).

    To show the results of a query from a Cursor you’d better use the SimpleCursorAdapter object, intead of the ArrayAdapter, this object helps you to map the results of the query (cursor) to the fields of your View (user interface). It would be something like that:

    public class YourListActivity extends ListActiviy{
    
        private SimpleCursorAdapter adp;
        private Cursor c;
    
        public void onCreate(Bundle savedInstanceState) {
                 super.onCreate(savedInstanceState);
    
                 ...
                 // from array: keeps the names of the Cursor columns.
                 String[] from = {"CURSOR_FIELD1","CURSOR_FIELD2", ...};
                 // to array: keeps the ids of the fields in your list item layout
                 int[] to = {R.id.itemLayoutfield1, R.id.itemLayoutfield2, ...};
                 // sets the basic layout of the ListActivity (the layout must contain a ListView element with the id called 'list').
                 setContentView(R.layout.listLayout);
    
                 // gets de cursor with the rows        
                 c = db.getAllCourses(); 
    
                 adp = new SimpleCursorAdapter(this, R.layout.itemLayout, c, from, to);             
                 setListAdapter(adp);
    
                 ...
         }
    }
    

    Important note: Keep in mind that the CursorAdapter class and it’s subclasses (i.e. SimpleCursorAdapter) needs that the primary key of the tables are named _id.

    The listLayout.xml should be similar to (notice that it has a ListView with id ‘list‘):

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:orientation="vertical"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content">
         <ListView android:id="@android:id/list"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"/>
     </LinearLayout>
    

    And the itemlayout.xml could be something like:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
                <TextView
                    android:id="@+id/itemLayoutfield1"
                    android:text="TextView" />
            </LinearLayout>
            <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent" >
                <TextView
                    android:id="@+id/itemLayoutfield2"
                    android:text="TextView" />          
            </LinearLayout>
            <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent" >
                <TextView
                    android:id="@+id/itemLayoutfield3"
                    android:text="TextView" />          
            </LinearLayout>
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a SQLite database within my android app, but my
I'm trying to create a child class of Android.App.Application to override OnCreate(), but I
I'm trying to create an animation in my android app. I want the animation
I'm trying to create an Android App that connects to a MySQL database. Is
I am trying to create a simple android app in Java but I have
I am trying to create an android app ..for that i want to know
i've been trying to create a map-related android app, but i realized that the
Im trying to create my own url scheme so my android app can get
I am trying to create an android app that has the following: Theme set
I am trying to create an android app which will show multiple web urls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.