title: App crashed when trying to get ID from SQLite
body: <p>When button is clicked, I want to get the data ID from SQLite. Unfortunately my app crashed. This happen when I try to retrieve the data ID from SQLite.</p>
  
  <p><strong>LogCat</strong></p>
  
  <pre><code>05-17 01:00:54.873  16093-16093/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
  android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
  at android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
  at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
  at android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java:68)
  at com.example.tony.easyactivity.MainActivity$1.onClick(MainActivity.java:49)
  </code></pre>
  
  <p><strong>Line 49</strong></p>
  
  <pre><code>int id = data.getInt(data.getColumnIndex("ID"));
  </code></pre>
  
  <p>Any help would be much appreciated.</p>
  
  <p>What I have tried:</p>
  
  <pre><code>btnAddData.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      boolean isInserted = myDb.insertData(editName.getText().toString());
                      if (isInserted) {
                          Cursor data = myDb.getID(editName.getText().toString());
                          int id = data.getInt(data.getColumnIndex("ID"));
                          Toast.makeText(getApplicationContext(), id + "", Toast.LENGTH_LONG).show();
                      }
                      else
                      {
                          myDb.addData(editName.getText().toString());
                          Toast.makeText(getApplicationContext(), "Not yet inserted ", Toast.LENGTH_LONG).show();
                      }
                  }
              });
          }
  </code></pre>
  
  <p><strong>DatabaseHelper</strong></p>
  
  <pre><code>public Cursor getID(String info) {
              SQLiteDatabase db = this.getWritableDatabase();
              Cursor c = db.rawQuery("Select ID from " + TABLE_NAME1 + " WHERE " + COL3 + "=?", new String[]{info});
              return c;
          }
  
          public boolean insertData(String name) {
              SQLiteDatabase db = this.getReadableDatabase();
              Cursor c = db.rawQuery("Select * from " + TABLE_NAME1 + " WHERE " + COL3 + "=?", new String[]{name});
              if (c.getCount() &gt; 0) {
                  return true;
              } else
                  return false;
          }
  
          public void addData(String name) {
              SQLiteDatabase db = this.getWritableDatabase();
              ContentValues cv=new ContentValues();
              cv.put(COL3, name);
              db.insert(TABLE_NAME1, null, cv);
          }
  </code></pre>