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 8662607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:46:28+00:00 2026-06-12T16:46:28+00:00

I’m developing an Android application (unfortunately) for my coursework. I need to use a

  • 0

I’m developing an Android application (unfortunately) for my coursework. I need to use a SimpleCursorAdapter to display a custom ListView of appointments. The constructor of the SimpleCursorAdapter takes a cursor as a parameter and this cursor needs to select all the columns that need to be displayed in the listView.

My problem is that everytime I run the application, it complains that: ‘column ‘_id’ does not exist’ but there is a column called id! Where am I going wrong?

Below is the relevant code:

public class AppointmentsDB {

    public static final String DATABASE_NAME = "appointment_db";
    public static final String DATABASE_TABLE = "appointment_table";
    private static final int DATABASE_VERSION = 1;

    public static final String KEY_ID = "_id";
    public static final String KEY_TITLE = "title";
    public static final String KEY_DESCRIPTION = "description";
    public static final String KEY_PRIORITY = "priority";
    public static final String KEY_DATE_TIME = "date_time";
    public static final String KEY_DURATION = "duration";
    public static final String KEY_ALARM_TIME = "alarm_time";

    private DatabaseHelper appointmentsDBHelper;
    private SQLiteDatabase appointmentsDB;
    private final Context context;

    public AppointmentsDB(Context context) {
        this.context = context;
        appointmentsDBHelper = new DatabaseHelper(context);
    }

    public SQLiteDatabase openReadableDatabase()
    {
        return appointmentsDBHelper.getReadableDatabase();
    }

    public SQLiteDatabase openWritableDatabase()
    {
        return appointmentsDBHelper.getWritableDatabase();
    }

    public long addAppointment(Appointment appointment)
    {
        //
    }

    public void close()
    {
        //
    }

    static class DatabaseHelper extends SQLiteOpenHelper {

        Context context;

        public DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);

            this.context = context;

        }

        @Override
        public void onCreate(SQLiteDatabase db) {

            StringBuilder query = new StringBuilder();
            query.append("CREATE TABLE "+DATABASE_TABLE+" ");
            query.append("(");
            query.append(KEY_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, ");
            query.append(KEY_TITLE+" TEXT NOT NULL, ");
            query.append(KEY_DESCRIPTION+" TEXT, ");
            query.append(KEY_PRIORITY+" INTEGER, ");
            query.append(KEY_DATE_TIME+" INTEGER, ");
            query.append(KEY_DURATION+" INTEGER, ");
            query.append(KEY_ALARM_TIME+" INTEGER");
            query.append(");");

            ContentValues test = new ContentValues();

            db.execSQL(query.toString());
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE IF EXISTS "+DATABASE_TABLE);
            onCreate(db);
        }

    }
}

MainActivity.java
public class MainActivity extends ListActivity {

private Cursor cursor;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AppointmentsDB dbHelper = new AppointmentsDB(this);

    // Execute query that selects all appointments.
    // Store cursor from that query in local variable 'cursor'.
    // Pass 'cursor' to SimpleCursorAdapter.
    // SimpleCursorAdapter uses 'cursor' to display all appointments in
    // listview.

    StringBuilder selectQuery = new StringBuilder();
    selectQuery.append("SELECT "+AppointmentsDB.KEY_ID+" ,");
    selectQuery.append(AppointmentsDB.KEY_TITLE + ", ");
    selectQuery.append(AppointmentsDB.KEY_DESCRIPTION + ", ");
    selectQuery.append(AppointmentsDB.KEY_PRIORITY + ", ");
    selectQuery.append(AppointmentsDB.KEY_DATE_TIME + ", ");
    selectQuery.append(AppointmentsDB.KEY_DURATION + ", ");
    selectQuery.append(AppointmentsDB.KEY_ALARM_TIME + " FROM "
            + AppointmentsDB.DATABASE_TABLE /*+ " "*/);
    selectQuery.append("ORDER BY " + AppointmentsDB.KEY_DATE_TIME
            + " ASC");

    cursor = dbHelper.openReadableDatabase().rawQuery(
            selectQuery.toString(), null);

    String[] columnNames = new String[]{""};
    int[] ids = new int[]{};

    AppointmentsCursorAdapter adapter = new AppointmentsCursorAdapter(this,R.layout.row,cursor,columnNames,ids);
    this.setListAdapter(adapter);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

// This class sets our customised layout for the ListView

class AppointmentsCursorAdapter extends SimpleCursorAdapter
{

    private Context context;
    private int layout;
    private int[] colours;

    public AppointmentsCursorAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) 
    {
        super(context, layout, c, from, to);

        this.context = context;
        this.layout = layout;
        //...
    }


    public View newView(Context context, Cursor cursor, ViewGroup parent)
    {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(layout, parent, false);

        TextView titleText = (TextView) view.findViewById(R.id.titleText);
        TextView priorityView = (TextView) view.findViewById(R.id.priorityView);
        TextView dateText = (TextView) view.findViewById(R.id.dateText);
        TextView monthText = (TextView) view.findViewById(R.id.monthText);
        TextView timeText = (TextView) view.findViewById(R.id.timeText);

        //...

        return view;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor)
    {
        super.bindView(view, context, cursor);


        TextView titleText = (TextView) view.findViewById(R.id.titleText);
        TextView priorityView = (TextView) view.findViewById(R.id.priorityView);
        TextView dateText = (TextView) view.findViewById(R.id.dateText);
        TextView monthText = (TextView) view.findViewById(R.id.monthText);
        TextView timeText = (TextView) view.findViewById(R.id.timeText);

        //...

    }
}

}

  • 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-12T16:46:29+00:00Added an answer on June 12, 2026 at 4:46 pm

    Try this:

    String[] columnNames = new String[]{AppointmentsDB.KEY_ID};
    int[] ids = new int[]{R.id.the_id_of_the_edittext_textview_or_wahtever_you_use_in_row_layout};
    

    Also, unlesss you want to do fancy things, maybe you can simply use a SimpleCursorAdapter like this:

    ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.row, cursor, columnNames, ids, CursorAdapter.NO_SELECTION);
    setListAdapter(adapter);
    

    I would also recommend using a ListFragment instead of ListActivity so you can reuse the list in other activities or situations (tablets…) if needed.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
In my XML file chapters tag has more chapter tag.i need to display chapters
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

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.