title: How to prevent app crashed after delete empty database
body: <p>i had been trying to prevent accidentally click on delete button when the data base is empty. It will crash after click.</p>
  
  <p>Database handler</p>
  
  <pre><code>public void deleteLastMessage(Class a) {
      SQLiteDatabase db = this.getWritableDatabase();
      db.delete(TABLE_NAME, KEY_MSG + " = ?",
              new String[] { String.valueOf(a.get_message()) });
      db.close();
  }
  public String getLastString() {
  
      String selectQuery = "SELECT  * FROM " + TABLE_NAME;
      SQLiteDatabase db = this.getReadableDatabase();
      Cursor cursor = db.rawQuery(selectQuery, null);
      cursor.moveToLast();
      LastString = cursor.getString(0);
      cursor.close();
      db.close();
      return LastString;
  }
  </code></pre>
  
  <p>Activity</p>
  
  <pre><code>public void deleteMessage(View v) {
      LastMessage = new SubliminalClass(db.getLastString());
      db.deleteLastMessage(LastMessage);
  </code></pre>
  
  <p>It work fine when there are data to delete, it crashed when there is no data.
  My data is a column of string.
  Referred to this <a href="https://stackoverflow.com/questions/30011426/application-crashes-while-reading-an-empty-table-in-android">Application crashes while reading an empty table in android</a> but to no avail.</p>
  
  <p>I have tried this below but still crashed when there is no data. </p>
  
  <pre><code>public boolean checkdb(){
      SQLiteDatabase db = this.getReadableDatabase();
      Cursor mCursor = db.rawQuery("SELECT * FROM " + TABLE_NAME, null);
      Boolean rowExists;
      String nullString="";
      if (nullString.equals(getLastString())) //todo change this
          // DO SOMETHING WITH CURSOR
          rowExists = false;
  
      else
      {
          // I AM EMPTY
          rowExists = true;
      }
      return rowExists;
  }
  </code></pre>
  
  <p>Anyone can help me solve this?</p>