I am using this to populate some fields from a database.
private void populateField() {
if(mRowId != null ){
Cursor Message = mDbHelper.fetchScheduledTask(mRowId);
startManagingCursor(Message);
Log.e("ROWID", mRowId.toString());
String commaText = (Message.getString(Message.getColumnIndexOrThrow(SmsDbAdapter.KEY_NUMBERS)));
numbers.setText(commaText);
When the activity is paused then resumed i get the error
10-17 11:15:13.123: ERROR/AndroidRuntime(15432): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
It points to this line of code.
String commaText = (Message.getString(TextMessage.getColumnIndexOrThrow(SmsDbAdapter.KEY_NUMBERS)));
How can i get rid or be defensive against this error.
You need to check if the cursor is empty before using it.
moveToFirst() will return false if there are no items in the cursor.