07-05 23:23:27.497: ERROR/AndroidRuntime(390): java.lang.RuntimeException: Unable to resume activity {com.fttech.books/com.fttech.books.creatBook}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
07-05 23:23:27.497: ERROR/AndroidRuntime(390): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
I keep getting these errors when i run i change views and it calls my onResume method to re-populate EditText fields. Here is my code for on resume:
protected void onResume(){
Log.v(tag, "In onResume!");
Cursor it = mDbHelper.fetchBook(mRowId);
super.onResume();
mDbHelper.open();
setRowIdFromIntent();
if (it.moveToFirst()) {
populateFields();
}
Here is my setRowIdFromIntent method:
private void setRowIdFromIntent(){
if(mRowId == null){
Bundle extras = getIntent().getExtras();
mRowId = extras != null
? extras.getLong(DbAdapter.KEY_ROWID)
:null;
}
PopulateFields method which retrieves information from the database if the activity is paused and then resumed, such as when i change from porttrait to landscape.
private void populateFields() {
if(mRowId != null){
Cursor books = mDbHelper.fetchBook(mRowId);
startManagingCursor(books);
bookTitle.setText(books.getString(books.getColumnIndexOrThrow(DbAdapter.KEY_BOOK)));
bookAuthor.setText(books.getString(books.getColumnIndexOrThrow(DbAdapter.KEY_AUTHOR)));
bookIsbn.setText(books.getString(books.getColumnIndexOrThrow(DbAdapter.KEY_ISBN)));
ratingBar.setRating(books.getFloat(books.getColumnIndex(DbAdapter.KEY_RATING)));