title: Android 3.0 Couldn't read row#, column# from cursor window
body: <p>I have an application that runs fine on android 2.1, but when trying to transition it to 3.0 I get a cursor error that I'm not familar with. </p>
  
  <blockquote>
    <p><strong>Java.lang.IllegalStateException:</strong> Couldn't read row0, column -1 from
    cursor window. Make sure cursor is initialized correctly before
    accessing data from it.</p>
  </blockquote>
  
  <p>All the data is storred in a SQLite database and this code works fine in android 2.1. Does a cursor have to be initialized differently in android 3.0?</p>
  
  <p>Listed below is my code.</p>
  
  <pre><code>private void OpenGroupData(){
  SQLiteDatabase db = openOrCreateDatabase(DATABASE_NAME,Context.MODE_PRIVATE,null);
  Cursor cur = db.rawQuery("SELECT groupid FROM properties GROUP BY GroupID" + ";" , null);
  LinearLayout glayout = (LinearLayout) findViewById(R.id.Grouplayout);
  LinearLayout gwindow = (LinearLayout) findViewById(R.id.groupwindow);
  
  TextView data = new TextView(this);
  glayout.addView(data);
  data.setText("");
  int ID = cur.getColumnIndex("groupid");
  int idvalue;
  
  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
  
  try{
      // Check if our result was valid.
      cur.moveToFirst();
      if (cur != null) {
  
          // Loop through all Results
          do {data = new TextView(this);
              data.setTextSize(20);
          data.setClickable(true);
          data.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                GroupClick(v);
              }
            });
          glayout.addView(data);
          idvalue = cur.getInt(ID);
          data.setId(idvalue);
          data.setText("Group: " + idvalue);
          }while(cur.moveToNext());
          } 
          cur.close();
          db.close();
          }   catch(Exception e) {
              Toast.makeText(getApplicationContext(), "Open Group Exception: " + e.toString(), Toast.LENGTH_SHORT).show();
          }
   }
  </code></pre>