我正在使用它填充數據庫中的一些字段。indexOutOfBounds當恢復活動
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);
當活動被暫停,然後繼續我的錯誤
10-17 11:15:13.123: ERROR/AndroidRuntime(15432): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
它指出了這行代碼。
String commaText = (Message.getString(TextMessage.getColumnIndexOrThrow(SmsDbAdapter.KEY_NUMBERS)));
我該如何擺脫或防禦這個錯誤。
固定的小錯字 - !你檢查 '而不是'(Message.moveToFirst() )...刪除了! ...如果光標能夠移動到第一個位置,則其中有有效的行。 – SBerg413
糟糕!感謝編輯。 – goto10