title: Android cursor index out of bounds exception
body: <p>I need to bind gridview in Android with simplecursor adapter, here is my code:</p>
  
  <pre><code> public class AndroidSqliteActivity extends Activity {
  private Veritabani ogrenciler; 
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
  
      requestWindowFeature(Window.FEATURE_NO_TITLE);      
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
      setContentView(R.layout.main);
      ogrenciler = new Veritabani(this);       
      final EditText adi=(EditText) findViewById(R.id.editText1); 
      final EditText soyadi=(EditText) findViewById(R.id.editText2);    
      Button verigonder=(Button) findViewById(R.id.verigonder);  
      Button button1 =(Button) findViewById(R.id.button1); 
      button1.setOnClickListener(new View.OnClickListener() {        
          public void onClick(View v) { 
              try{
  
              Intent i = new Intent(AndroidSqliteActivity.this, AndroidVeriActivity.class);
              startActivity(i);
              }
              catch(RuntimeException e)
              {
                  Log.e("ERROR", "ERROR IN CODE: " + e.toString());
  
              }
  
          }
          });
      verigonder.setOnClickListener(new View.OnClickListener() {        
          public void onClick(View v) { 
              try{                 
                  KayitEkle(adi.getText().toString(),soyadi.getText().toString()); 
                  Cursor cursor = KayitGetir();  
                  KayitGoster(cursor);        
                  }
              catch (SQLiteException e) {  
  
                               Log.d("eHata", e.getLocalizedMessage());  
                           }  
              finally{            
                  ogrenciler.close();    
                  }             
              }        
          });    
      } 
  private void KayitEkle(String isim, String soyad){     
      SQLiteDatabase db = ogrenciler.getWritableDatabase(); 
      ContentValues veriler = new ContentValues();    
      veriler.put("isim", isim);     
      veriler.put("soyad",soyad); 
      db.insertOrThrow("ogrenciisim", null, veriler);    
      } 
  
  private Cursor KayitGetir(){  
      SQLiteDatabase db = ogrenciler.getReadableDatabase();  
      Cursor cursor = db.query("ogrenciisim", new String[] {"id", "isim", "soyad"}, null, null, null, null, null);  
      startManagingCursor(cursor);      
      return cursor;    
      } 
  private void KayitGoster(Cursor cursor){ 
  
      try{
      final GridView grid=(GridView) findViewById(R.id.gridView1); 
  
      String[] columns = new String[] { "id", "isim", "soyad" };
      int[] to = new int[] { R.id.textView122, R.id.textView222, R.id.textView322 }; 
      SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.gridview, cursor, columns, to);  
      grid.setAdapter(mAdapter);
      }
      catch(Exception e)
      {
          Log.d("eHata", e.getLocalizedMessage());  
      }
      } 
  </code></pre>
  
  <p>}</p>
  
  <p>And here is my database class:</p>
  
  <pre><code>public class Veritabani extends SQLiteOpenHelper {
  private static final String VERITABANI = "Ogrenciler";
  private static final int SURUM = 1;
  
  public Veritabani(Context con)
  {
  super (con,VERITABANI,null,SURUM);
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
  // TODO Auto-generated method stub
  db.execSQL("create table ogrenciisim(id integer primary key, isim text, soyad text);");
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  db.execSQL("drop table if exist ogrenciisim");
  onCreate(db);
  
  }
  }
  </code></pre>
  
  <p>But it gives an error "index -1 requested with size of 18(16-20)" What am I doing wrong??</p>
  
  <p>PS:I changed it as Barak mentioned, but now it gives th error : "Column id doesnt exist"
  Thanks indeed</p>