title: Android SQLite checking if tables contain rows
body: <p>So I'm working on a game for android and I'm currently stuck at the 'load savegame' button in the main menu. 
  This button calls methods that read data from the database and write it into a resource class from which on this data will be accessed.</p>
  
  <p><strong>The problem is:</strong> I want to disable the load button if there are no rows in the tables, which means that no savegame exists.</p>
  
  <p>To do this I used the following method:</p>
  
  <pre><code>public boolean checkForTables(){
      boolean hasTables;
      String[] column = new String[1];
      column[0] = "Position";
      Cursor cursor;
      cursor = db.query("itemtable", column, null, null, null, null, null);
      if(cursor.isNull(0) == true){
          hasTables=false;
      }else{
          hasTables=true;
      }
      return hasTables;
  </code></pre>
  
  <p>As you can see it starts a query on one of the database tables and checks if the 0-column, which is the only one that should be in this cursor, is null. ATM I can't check logcat results on this call because I seem to have some problems with it, but it seems that the query throws an exception because the table is empty.</p>
  
  <p>Any idea to check the tables for rows?</p>
  
  <p><strong><em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>_EDIT_<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em></strong></p>
  
  <p><strong>NOTE: I checked the database and it sure is empty</strong></p>
  
  <p>Okay I used a rawQuery on the table but the approach with count-statement produced an error, so I'm using </p>
  
  <pre><code>public boolean checkForTables(){
          boolean hasTables;
  
          Cursor cursor = db.rawQuery("SELECT * FROM playertable", null);
  
          if(cursor.getCount() == 0){
              hasTables=false;
          if(cursor.getCount() &gt; 0){
              hasTables=true;
          }
  
          cursor.close();
          return hasTables;
      }
  </code></pre>
  
  <p>I'm using this method to decide whether or not to disable the loadGame-button which looks like this:</p>
  
  <pre><code>loadGame = (ImageButton) findViewById(R.id.loadButton);
      loadGame.setEnabled(databaseAccess.checkForTables());
      loadGame.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              databaseAccess.loadPlayer();
              databaseAccess.loadItems();
              databaseAccess.dropTables();
  
          }
      });
  </code></pre>
  
  <p>So if checkForTables gets a rowcount of != 0 it will return true and therefore enable the Button, or disable it if rowcount = 0</p>
  
  <p>Amusingly, although the tables are empty, checkForTables() returns true because getCount() seems to return a != 0 value - I just don't get it.</p>