Search in sources :

Example 16 with CursorIndexOutOfBoundsException

use of android.database.CursorIndexOutOfBoundsException in project newsrob by marianokamp.

the class DashboardListActivity method onContextItemSelected.

@Override
protected boolean onContextItemSelected(MenuItem item, int selectedPosition) {
    String label = null;
    int ord = -99;
    try {
        Cursor c = (Cursor) sca.getItem(selectedPosition);
        label = c.getString(0);
        ord = c.getInt(3);
    } catch (CursorIndexOutOfBoundsException cioobe) {
    // label stays null
    }
    if (label == null)
        return false;
    if (item.getItemId() == MENU_ITEM_MARK_ALL_READ_ID) {
        boolean showOnlyNotes = ord == -7 && "notes".equals(label);
        Long feedId = null;
        if (showOnlyNotes) {
            feedId = getEntryManager().findNotesFeedId();
            label = null;
        }
        DBQuery dbq = getDbQuery();
        instantiateMarkAllReadDialog(label, feedId, dbq.getStartDate(), dbq.getDateLimit(), dbq.isSortOrderAscending(), dbq.getLimit());
    }
    // getEntryManager().requestMarkAllAsRead(label, null, 0, handler);
    return true;
}
Also used : CursorIndexOutOfBoundsException(android.database.CursorIndexOutOfBoundsException) Cursor(android.database.Cursor)

Example 17 with CursorIndexOutOfBoundsException

use of android.database.CursorIndexOutOfBoundsException in project android_frameworks_base by crdroidandroid.

the class DatabaseCursorTest method testCursor1.

@MediumTest
public void testCursor1() throws Exception {
    populateDefaultTable();
    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    int dataColumn = c.getColumnIndexOrThrow("data");
    // The cursor should ignore text before the last period when looking for a column. (This
    // is a temporary hack in all implementations of getColumnIndex.)
    int dataColumn2 = c.getColumnIndexOrThrow("junk.data");
    assertEquals(dataColumn, dataColumn2);
    assertSame(3, c.getCount());
    assertTrue(c.isBeforeFirst());
    try {
        c.getInt(0);
        fail("CursorIndexOutOfBoundsException expected");
    } catch (CursorIndexOutOfBoundsException ex) {
    // expected
    }
    c.moveToNext();
    assertEquals(1, c.getInt(0));
    String s = c.getString(dataColumn);
    assertEquals(sString1, s);
    c.moveToNext();
    s = c.getString(dataColumn);
    assertEquals(sString2, s);
    c.moveToNext();
    s = c.getString(dataColumn);
    assertEquals(sString3, s);
    c.moveToPosition(-1);
    c.moveToNext();
    s = c.getString(dataColumn);
    assertEquals(sString1, s);
    c.moveToPosition(2);
    s = c.getString(dataColumn);
    assertEquals(sString3, s);
    int i;
    for (c.moveToFirst(), i = 0; !c.isAfterLast(); c.moveToNext(), i++) {
        c.getInt(0);
    }
    assertEquals(3, i);
    try {
        c.getInt(0);
        fail("CursorIndexOutOfBoundsException expected");
    } catch (CursorIndexOutOfBoundsException ex) {
    // expected
    }
    c.close();
}
Also used : CursorIndexOutOfBoundsException(android.database.CursorIndexOutOfBoundsException) SQLiteCursor(android.database.sqlite.SQLiteCursor) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

CursorIndexOutOfBoundsException (android.database.CursorIndexOutOfBoundsException)17 Cursor (android.database.Cursor)14 SQLiteCursor (android.database.sqlite.SQLiteCursor)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Entry (com.newsrob.Entry)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 Timing (com.newsrob.util.Timing)1 File (java.io.File)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1