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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:07:05+00:00 2026-05-31T16:07:05+00:00

I have a database with event names and dates. I am trying to create

  • 0

I have a database with event names and dates. I am trying to create an expandablelistview using cursors that will have the events grouped by event date.

I’m not finding a lot of information relevant to my situation regarding it. The example in the SDK is using a content provider and I haven’t read-up/experimented with that yet and I already have the database helper set up the old way.

I found what I thought was a good example here and tried to adapt it to my use, however it is crashing and I can’t figure out what I’ve done wrong.

my code

import android.app.ExpandableListActivity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.SimpleCursorTreeAdapter;

public class ExpandableListTestActivity extends ExpandableListActivity {

    private AttendanceDB mDbHelper;  
    private Cursor mGroupsCursor; 
    private int mGroupIdColumnIndex; 
    private MyExpandableListAdapter mAdapter; 

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

                    mDbHelper = new AttendanceDB(this); 
                    mDbHelper.open(); 
                    fillData(); 
    } 

    private void fillData() { 
                    mGroupsCursor = mDbHelper.fetchGroup();   
                    startManagingCursor(mGroupsCursor); 

                    mAdapter = new MyExpandableListAdapter(mGroupsCursor,this, 
                                                    android.R.layout.simple_expandable_list_item_1, 
                                                    android.R.layout.simple_expandable_list_item_1, 
                                                    new String[] { AttendanceDB.EVENT_DATE }, 
                                                    new int[] { android.R.id.text1 }, 
                                                    new String[] { AttendanceDB.EVENT_NAME }, 
                                                    new int[] { android.R.id.text1 }); 
                    setListAdapter(mAdapter); 
    } 

    public class MyExpandableListAdapter extends SimpleCursorTreeAdapter { 

                    public MyExpandableListAdapter(Cursor cursor, Context context, 
                                                    int groupLayout, int childLayout, String[] groupFrom, 
                                                    int[] groupTo, String[] childrenFrom, int[] childrenTo) { 
                                    super(context, cursor, groupLayout, groupFrom, groupTo, 
                                                                    childLayout, childrenFrom, childrenTo); 
                    } 

                    @Override 
                    protected Cursor getChildrenCursor(Cursor groupCursor) { 
                                    Cursor childCursor = mDbHelper 
                                                                    .fetchChildren(groupCursor.getString(groupCursor.getColumnIndex(AttendanceDB.EVENT_DATE))); 
                                    startManagingCursor(childCursor); 
                                    return childCursor; 
                    } 
    } 
}

When I run this code I get the following:

E/AndroidRuntime(30329): FATAL    EXCEPTION: main
E/AndroidRuntime(30329): java.lang.RuntimeException: Unable to start activity ComponentInfo{cdc.workshopapps.explist/cdc.workshopapps.explist.ExpandableListTestActivity}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it
E/AndroidRuntime(30329):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
E/AndroidRuntime(30329):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
E/AndroidRuntime(30329):    at android.app.ActivityThread.access$500(ActivityThread.java:122)
E/AndroidRuntime(30329):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
E/AndroidRuntime(30329):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(30329):    at android.os.Looper.loop(Looper.java:132)
E/AndroidRuntime(30329):    at android.app.ActivityThread.main(ActivityThread.java:4123)
E/AndroidRuntime(30329):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(30329):    at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime(30329):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
E/AndroidRuntime(30329):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
E/AndroidRuntime(30329):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(30329): Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it
E/AndroidRuntime(30329):    at android.database.CursorWindow.getLong_native(Native Method)
E/AndroidRuntime(30329):    at android.database.CursorWindow.getLong(CursorWindow.java:436)
E/AndroidRuntime(30329):    at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:56)
E/AndroidRuntime(30329):    at android.widget.CursorTreeAdapter$MyCursorHelper.getId(CursorTreeAdapter.java:437)
E/AndroidRuntime(30329):    at android.widget.CursorTreeAdapter.getGroupId(CursorTreeAdapter.java:192)
E/AndroidRuntime(30329):    at android.widget.ExpandableListConnector.getItemId(ExpandableListConnector.java:421)
E/AndroidRuntime(30329):    at android.widget.AdapterView.getItemIdAtPosition(AdapterView.java:744)
E/AndroidRuntime(30329):    at android.widget.AdapterView.setSelectedPositionInt(AdapterView.java:1087)
E/AndroidRuntime(30329):    at android.widget.ListView.setAdapter(ListView.java:458)
E/AndroidRuntime(30329):    at android.widget.ExpandableListView.setAdapter(ExpandableListView.java:469)
E/AndroidRuntime(30329):    at android.app.ExpandableListActivity.setListAdapter(ExpandableListActivity.java:246)
E/AndroidRuntime(30329):    at cdc.workshopapps.explist.ExpandableListTestActivity.fillData(ExpandableListTestActivity.java:36)
E/AndroidRuntime(30329):    at cdc.workshopapps.explist.ExpandableListTestActivity.onCreate(ExpandableListTestActivity.java:22)
E/AndroidRuntime(30329):    at android.app.Activity.performCreate(Activity.java:4397)
E/AndroidRuntime(30329):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
E/AndroidRuntime(30329):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
E/AndroidRuntime(30329):    ... 11 more

Which I take to mean there’s something wrong with the columns I’m returning in my cursor. But if I change the filldata() method to the following (just to check my cursors/columns):

mGroupsCursor = mDbHelper.fetchGroup();
startManagingCursor(mGroupsCursor);
mGroupsCursor.moveToFirst();
String Text1 = mGroupsCursor.getString(mGroupsCursor.getColumnIndex(AttendanceDB.EVENT_DATE));
Toast.makeText(this, Text1, Toast.LENGTH_LONG).show();
Cursor childCursor = mDbHelper
        .fetchChildren(mGroupsCursor.getString(mGroupsCursor.getColumnIndex(AttendanceDB.EVENT_DATE)));
startManagingCursor(childCursor);
childCursor.moveToFirst();
String Text2 = childCursor.getString(childCursor.getColumnIndex(AttendanceDB.EVENT_NAME));
Toast.makeText(this, Text2, Toast.LENGTH_LONG).show();

The toasts output the expected event date and event name data, so I’m at a loss as to where I’ve gone wrong.

Other (perhaps) relevant code:

public Cursor fetchGroup() {
    String query ="SELECT DISTINCT date FROM events"; 
      return mDb.rawQuery(query,null); 
}

public Cursor fetchChildren(String date) {
    Cursor c = mDb.query(EVENT_TABLE, new String[] { EVENT_ROWID,
            EVENT_NAME }, EVENT_DATE + "='" + date + "'" ,
            null, null, null, null);

return c;
}

Any help would be greatly appreciated.

  • 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-31T16:07:06+00:00Added an answer on May 31, 2026 at 4:07 pm

    The CursorTreeAdapter needs a “_id” field in the cursor. If you have this field in your database just add it to your fetchGroup and fetchChildren query.

    Otherwise add “rowid as _id”. This uses SQLites internal numbering of rows.

    Android Reference CursorTreeAdapter

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

Sidebar

Related Questions

I have a database that will store events. Each event has different activities. The
I have a database that contains a date and we are using the MaskedEditExtender
I have a database with event information, including date (in MMDDYYYY format). is it
I have button, which fires an event, that deletes a record from the database.
I have an Event database loaded into Core Data that has duplicate Event titles.
I have some dates/events in a database, and I'd like to pull them out
I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
i have database table like this +-------+--------------+----------+ | id | ip | date |
I have an application that is already using the Spring Framework and Spring JDBC
I have a Java class representing an event that contains some data, and also

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.