我通過在EditText
中輸入密鑰來訪問SQLiteDatabase
中的數據。每當我輸入一些錯誤的密鑰時,我的應用程序就不會停止。我不希望我的申請停止,而是我想在這裏表示敬酒。
我該怎麼做?如何處理Sqlite CursorIndexOutOfBound異常
try{
Log.e("table", table_name);
mDb = mDbHelper.getReadableDatabase();
Cursor c = mDb.rawQuery("SELECT name,address1,address2,address3,tariff,sup_type,load,load_unit,meter_no,pole_cd,mst FROM "+table_name+" WHERE acc_id = '"+ i +" ' ", null);
if (c.equals(null))
{
c.moveToFirst();
Log.e("c", "i am null"+ c.toString());
}
else if (c!=null) {
c.moveToNext();
Log.e("c", "i am notnull" + c.toString());
}
return c;
}
catch (SQLException mSQLException)
{
Log.e(TAG, "getTestData >>"+ mSQLException.toString());
throw mSQLException;
}
安置自己的堆棧跟蹤,倒數..更改,如果條件如果(C!= NULL && c.moveToFirst()){...} – Tarun
你嘗試過'c == null'而不是'c.equals(null)'嗎? –
當遊標爲空時,您不能執行'c.moveToFirst();'。所以只檢查'如果(c.moveToFirst()){//空}其他{//不是null}'大家的幫助 –