private void checkPosition() { int pos = mInnerCursor.getPosition(); int count = mInnerCursor.getCount(); if (-1 == pos || count == pos) { throw new CursorIndexOutOfBoundsException(pos, count); } }
public VizContract.Downloads.Status getDownloadStatus(int position) { Cursor cursor = (Cursor) mAdapter.getItem(position); // this is cruft left-over from a previous bug which I do not think // exists anymore b/c we no longer remove a Download behind the users // back (we used to do this when the download failed) if (cursor.getCount() == 0) { return VizContract.Downloads.Status.FAILED; } int statusInt = VizContract.Downloads.Status.FAILED.valueOf(); try { statusInt = cursor.getInt(cursor.getColumnIndex(DownloadsColumns.STATUS)); } catch(CursorIndexOutOfBoundsException e) { Log.w("threw a cursorIndexOfBoundsException"); } return VizContract.Downloads.Status.fromInt(statusInt); }
public T getGraphObject() { if (this.pos < 0) throw new CursorIndexOutOfBoundsException("Before first object."); if (this.pos >= this.graphObjects.size()) throw new CursorIndexOutOfBoundsException("After last object."); return (GraphObject)this.graphObjects.get(this.pos); }
@Test(expected = CursorIndexOutOfBoundsException.class) public void shouldThrowIndexOutOfBoundsExceptionForInvalidColumnLastRow() throws Exception { MatrixCursor cursor = new MatrixCursor(new String[]{"a", "b", "c"}); cursor.addRow(new Object[]{"foo", 10L, 0.1f}); cursor.moveToFirst(); cursor.moveToNext(); cursor.getString(0); }
@Override public T getGraphObject() { if (pos < 0) { throw new CursorIndexOutOfBoundsException("Before first object."); } if (pos >= graphObjects.size()) { throw new CursorIndexOutOfBoundsException("After last object."); } return graphObjects.get(pos); }
public String getPassword() { SQLiteDatabase db = mDbHelper.getReadableDatabase(); Cursor cursor = db.query(ThreadHelper.DB_USER_TABLE, new String[] { ThreadHelper.DB_PASSWORD }, ThreadHelper.DB_ID + "=?", new String[] { "0" }, null, null, null, null); if (cursor != null) cursor.moveToFirst(); try { return cursor.getString(0); } catch (CursorIndexOutOfBoundsException e) { if (th.D) Log.d(TAG, e.getMessage()); } return null; }
public String getName() { SQLiteDatabase db = mDbHelper.getReadableDatabase(); Cursor cursor = db.query(ThreadHelper.DB_USER_TABLE, new String[] { ThreadHelper.DB_NAME }, ThreadHelper.DB_ID + "=?", new String[] { "0" }, null, null, null, null); if (cursor != null) cursor.moveToFirst(); try { return cursor.getString(0); } catch (CursorIndexOutOfBoundsException e) { if (th.D) Log.d(TAG, e.getMessage()); } return null; }
public boolean issetUser() { SQLiteDatabase db = mDbHelper.getReadableDatabase(); try { Cursor cursor = db.query(ThreadHelper.DB_USER_TABLE, new String[] { ThreadHelper.DB_NAME }, ThreadHelper.DB_ID + "=?", new String[] { "0" }, null, null, null, null); if (cursor != null) cursor.moveToFirst(); cursor.getString(0); return true; } catch (CursorIndexOutOfBoundsException e) { if (th.D) Log.d(TAG, e.getMessage()); } return false; }
public String getPublicKey() { String result = null; SQLiteDatabase db = mDbHelper.getReadableDatabase(); Cursor cursor = db.query(ThreadHelper.DB_USER_TABLE, new String[] { ThreadHelper.DB_PUBLIC }, ThreadHelper.DB_ID + "=?", new String[] { "0" }, null, null, null, null); try { if (cursor != null) cursor.moveToFirst(); result = cursor.getString(0); } catch (CursorIndexOutOfBoundsException e) { if (th.D) Log.d(TAG, e.getMessage()); } return result; }
public String getPrivateKey() { String result = null; SQLiteDatabase db = mDbHelper.getReadableDatabase(); Cursor cursor = db.query(ThreadHelper.DB_USER_TABLE, new String[] { ThreadHelper.DB_PRIVATE }, ThreadHelper.DB_ID + "=?", new String[] { "0" }, null, null, null, null); try { if (cursor != null) cursor.moveToFirst(); result = cursor.getString(0); } catch (CursorIndexOutOfBoundsException e) { if (th.D) Log.d(TAG, e.getMessage()); } return result; }
/** * Get the main email address of the contact * @param contactID The last known ContactID of the contact * @param c The context to run in * @return String representation of their email address * @throws android.database.CursorIndexOutOfBoundsException */ public static HashMap<String,String> getContactsEmailAddress(String contactID, Context c) throws CursorIndexOutOfBoundsException { /* * For some shitting reason, using ContactsContract.CommonDataKinds.Phone works instead of Email? * Leaving it anyway, might just be some stupid HTC Sense 5 bug */ HashMap<String,String> emails = new HashMap<String,String>(); for(int i=0;i<=typesEmail.length-1;i++){ String[] whereArgs = new String[] {String.valueOf(contactID), String.valueOf(typesEmail[i])}; String email = queryContactForEmail(c, whereArgs); if(email!=null){ if(ContactsContract.CommonDataKinds.Phone.TYPE_HOME==typesEmail[i]){ emails.put("Home", email); } else if(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE==typesEmail[i]){ emails.put("Other", email); } else if(ContactsContract.CommonDataKinds.Phone.TYPE_WORK==typesEmail[i]){ emails.put("Work", email); } } } return emails; }
/** * Lookup the most recent entry in the database * @return Debt representation of most recent debt entered into database * @throws java.text.ParseException * @throws NullPointerException * @throws android.database.sqlite.SQLiteException * @throws android.database.CursorIndexOutOfBoundsException */ public Debt getMostRecentDebt() throws ParseException, NullPointerException, SQLiteException, CursorIndexOutOfBoundsException{ SQLiteDatabase db = getReadableDatabase(); Cursor c; c = db.query(Names.D_TABLENAME, null, null, null, null, null, null); c.moveToLast(); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); db.close(); return new Debt(c.getInt(0), c.getString(1), sdf.parse(c.getString(2)), new BigDecimal(c.getString(2)), c.getString(3)); }
@Override protected String doInBackground(String... sUrl) { sqliteHelper = new SQLiteOpenHelperCurrency( ConverterInterface.thisContext); String[] code = new String[1]; db = sqliteHelper.getReadableDatabase(); Cursor cursor = null; try { for (int n = 0; n <= currencyCodes.length - 1; n++) { for (int k = 0; k <= currencyCodes.length - 1; k++) { code[0] = String.valueOf(n * (currencyCodes.length) + k + 1); cursor = db.rawQuery( "SELECT currency from currencies WHERE _id=?", code); cursor.moveToFirst(); currencies[n][k] = Double.valueOf(cursor .getString(cursor.getColumnIndex("currency"))); cursor.close(); } } } catch (CursorIndexOutOfBoundsException e) { Converter.CurrencyDatabase.delete(); } finally { if (cursor != null) cursor.close(); } publishProgress(0); return null; }