title: How to resolve CursorIndexOutOfBounds
body: <p>This has stumped me so far.</p>
  
  <p>I keep getting a CursorIndexOutOfBounds when trying to run a this specific query.</p>
  
  <pre><code>    Cursor c = db.rawQuery("SELECT * FROM table WHERE _id='2'" , null);
  </code></pre>
  
  <p>But the odd thing is above that query I am running a loop that outputs all of the _id values from that table. It outputs 1 to 100 so I know that the value is there. Also I output all of the columns and they are all there as I expect.</p>
  
  <p>Even though I am pretty sure there are values and in the correct columns this line of code keeps thowing the CursorIndexOutOfBounds. Could anyone suggest avenues to approach this problem.</p>
  
  <pre><code>    numval = c.getInt(c.getColumnIndex("_id"));
  </code></pre>
  
  <p>Logcat entry</p>
  
  <pre><code>11-21 11:35:09.367: ERROR/AndroidRuntime(11664): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
  </code></pre>
  
  <p>EDIT</p>
  
  <p>Here is the exact code I am running. I am still getting the error I posted just above this sentence.</p>
  
  <pre><code>    Cursor cur = db.rawQuery("SELECT * FROM table" , null);
      cur.moveToFirst();
      while (cur.isAfterLast() == false) {
  
          numval = cur.getInt(cur.getColumnIndex("_id"));
          String numvalval = Integer.toString(numval);
          Log.e("RESULT",numvalval);
          cur.moveToNext();
      }
      cur.close();
      Cursor ti = db.rawQuery("PRAGMA table_info(table)", null);
      if ( ti.moveToFirst() ) {
          do {
              Log.e("COLUMN NAMES","col: '" + ti.getString(1) +"'");
          } while (ti.moveToNext());
      }
      ti.close();
      Cursor c = db.rawQuery("SELECT * FROM table WHERE _id='2'" , null);
      c.moveToFirst();
                  numval      = c.getInt(c.getColumnIndex("_id"));
  </code></pre>
  
  <p>It is outputting</p>
  
  <pre><code>11-21 13:27:25.906: ERROR/RESULT(13377): 1
  11-21 13:27:25.906: ERROR/RESULT(13377): 2
  11-21 13:27:25.910: ERROR/COLUMN NAMES(13377): col: '_id'
  11-21 13:27:25.910: ERROR/COLUMN NAMES(13377): col: 'country'
  </code></pre>