I try to implement the following code
In the activity.java file
DatabaseEvent mDbHelper = new DatabaseEvent(getApplicationContext());
mDbHelper.open();
Cursor notesCursor = mDbHelper.fetchEvent();
startManagingCursor(notesCursor);
String[] from = new String[]{DatabaseEvent.KEY_ETITLE, DatabaseEvent.KEY_DISTANCE, DatabaseEvent.KEY_IMGNAME, DatabaseEvent.KEY_DESCRIPTION, DatabaseEvent.KEY_EID};
int[] to = new int[]{R.id.title, R.id.duration, R.id.list_image, R.id.artist, R.id.id};
SimpleCursorAdapter event =
new SimpleCursorAdapter(getApplicationContext(), R.layout.list_row, notesCursor, from, to);
In the DatabaseEvent.java
public long createEvent(String title, String distance, String imgname, String description, String eid) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_ETITLE, title);
initialValues.put(KEY_DISTANCE, distance);
initialValues.put(KEY_IMGNAME, imgname);
initialValues.put(KEY_DESCRIPTION, description);
initialValues.put(KEY_EID, eid);
Log.v("INFO1","inserting db");
return mDb.insert(EVENT_TABLE, null, initialValues);
}
public Cursor fetchEvent() {
Log.v("INFO1","fetching db");
Cursor mCursor = mDb.query(EVENT_TABLE, new String[] {KEY_ROWID, KEY_ETITLE, KEY_DISTANCE,
KEY_IMGNAME, KEY_DESCRIPTION, KEY_EID}, null, null,null,null, KEY_DISTANCE+" ASC");
return mCursor;
}
On the logcat, I can clearly see that the log message "inserting db" is printed three times mean the data date really added to the database, but the log message "fetching db" printed once and give me the flowing error says:
CursorIndexOutOfBoundException index -1, requsted, with a size of 60,
I tried different function like moveToFirst() and moveToNext() but still couldn't solve the problem, any one could give me hand, any help will be greately appreciated!