mercredi 2 décembre 2015

Android sqlite database getallRows() checking for null gives error

I have tried all forms of error checking in order to catch and deal with the error checking but nothing works and it keeps crashing.

Cursor cursor = null;
    try{
     cursor  = mydb.getAllRows();
    }finally{
        if(cursor == null)
        {
            // I want to exit here and do nothing. 
            // Crashes here. 

        }
        else{if(cursor.moveToFirst()){
             do{
                String id= cursor.getString(0);
                String text = cursor.getString(1);
                String cooktime = cursor.getString(2);
                String difficulty = cursor.getString(3);
                String making = cursor.getString(4);




                }while(cursor.moveToNext());
             }
          cursor.close();

        }

    }

I know mydb has nothing in it, so how do I error check with this issue so it doesn't crash.

Aucun commentaire:

Enregistrer un commentaire