android - How to Handle Sqlite CursorIndexOutOfBound exception -


i accessing data sqlitedatabase entering key in edittext. whenever enter wrong key,which not in database application stops. don't want application stop, instead want show toast here.
how can this?

  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 "+table_name+"  acc_id = '"+ +" ' ", null);          if (c.equals(null))          {             c.movetofirst();             log.e("c", "i null"+ c.tostring());         }          else if (c!=null) {             c.movetonext();             log.e("c", "i notnull" + c.tostring());         }          return c;       }      catch (sqlexception msqlexception)       {          log.e(tag, "gettestdata >>"+ msqlexception.tostring());          throw msqlexception;      }  

always check cursor count before using cursor

            if (cursor != null && cursor.getcount() > 0) {                 // logic goes here             } else {                 toast.maketext(getapplicationcontext(), "no record found", 1000).show();             } 

Comments