CursorIndexOutOfBoundsException: Index 0 Requested, With A Size Of 0
When you try to display the contents of a database in TextView pops up here this error: 02-27 19:44:59.519: E/AndroidRuntime(5696): FATAL EXCEPTION: main 02-27 19:44:59.519: E/Andr
Solution 1:
You are getting no values in the cursor, like MH. pointed in the comments. You can change your code to the following to avoid CursorIndexOutOfBoundsException
@Override
protected void onPostExecute(Cursor mCursor) {
super.onPostExecute(mCursor);
if(mCursor.moveToFirst()){ // перемещение к первому элементу
// получение индекса столбца для каждого элемента данных
int nameIndex = mCursor.getColumnIndex(COLUMN_NAME);
int phoneIndex = mCursor.getColumnIndex(COLUMN_PHONE);
int birthdayIndex = mCursor.getColumnIndex(COLUMN_BIRTHDAY);
int passportIndex = mCursor.getColumnIndex(COLUMN_PASSPORT_SN);
int adressIndex = mCursor.getColumnIndex(COLUMN_ADRESS);
int siteIndex = mCursor.getColumnIndex(COLUMN_SITE);
// заполнение компонентов TextViews выбранными данными
nameTV.setText(mCursor.getString(nameIndex));
phoneTV.setText(mCursor.getString(phoneIndex));
birthdayTV.setText(mCursor.getString(birthdayIndex));
passportTV.setText(mCursor.getString(passportIndex));
adressTV.setText(mCursor.getString(adressIndex));
siteTV.setText(mCursor.getString(siteIndex));
}
mCursor.close(); // закрытие курсора результата
sdb.close(); // закрытие подключения к базе данных
}
Hope it helps.
Post a Comment for "CursorIndexOutOfBoundsException: Index 0 Requested, With A Size Of 0"