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

  • SEARCH
  • Home
  • 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 6137687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:45:29+00:00 2026-05-23T17:45:29+00:00

Here is my code for a simple cursor adapter. public class CursorList extends ListActivity

  • 0

Here is my code for a simple cursor adapter.

public class CursorList extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    DatabaseAdapter da = new DatabaseAdapter(this, "mydb.sqlite");

    da.open();
    Cursor cur = da.fetchAllRecords("Doctors", new String[]{"FirstName"});
    startManagingCursor(cur);

    cur.moveToFirst();
    do {
        Log.v("Info", cur.getString(cur.getColumnIndex("FirstName")));
    } while(cur.moveToNext());

    cur.moveToFirst();

    String[] from = new String[]{"FirstName"};
    int[] to = new int[]{R.id.row};

    SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.row_item, cur, from, to);

    setListAdapter(sca);
    }
}

The data records are displayed correctly in the log, but the code stops working when it reaches the

SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.row_item, cur, from, to);

line.

The error I get is :

ERROR/AndroidRuntime(26746): Uncaught handler: thread main exiting due to uncaught exception
ERROR/AndroidRuntime(26746): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.arnab.cursorlist/com.arnab.cursorlist.CursorList}:
java.lang.IllegalArgumentException: column '_id' does not exist

Where am I going wrong?

Why does it give an error that column ‘_id’ doesn’t exist? Is it a necessary column which we have to have in our tables?

EDIT:

When I put the cursor related code in a try catch block, something like this:

try {
        SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.row_item, cur, from, to);

        setListAdapter(sca);
    }
    catch(Exception E) {
        Log.v("Error", E.getMessage());
    }

I get the message :

VERBOSE/Error(1026): column '_id' does not exist

@Rasel : Here is the fetchAllRecords method

public Cursor fetchAllRecords(String table, String columns[]) {
    return mDb.query(table, columns, null, null, null, null, null);     
}
  • 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-05-23T17:45:29+00:00Added an answer on May 23, 2026 at 5:45 pm

    Why does it give an error that column ‘_id’ doesn’t exist? Is it a necessary column which we have to have in our tables?

    Yes, if you want to use your database information in a cursor adapter. The adapter uses it for internal purposes. Your table must have an ‘_id’ column, and you must select it in your query (so it is in the Cursor result set). You do not have to actually display it in your ListView.

    Revised for Posterity

    Instead of actually adding the ‘_id’ column, you can SELECT your own ‘id’ column as ‘_id’, and it will work just the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a simple piece of code: import java.io.*; public class Read { public
So here is the simple code: [System.ComponentModel.DefaultValue(true)] public bool AnyValue { get; set; }
I'll make it simple, here's the code I've got. public ActionResult DeleteNonCIStaffUser(int id) {
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here is a simple code that shows what I think is a bug when
enter code here Hi All, I have a simple windows service application that connects
I've got a quite strange problem here. I'm calling some simple code via Ajax.Updater:
What is the best way to implement simple pagination? Here is the code im
I have -- what I think -- is a simple question. Here's my code:
I want to write a simple web proxy, for exercise. Here's the code I

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.