title: getting error when insert data in sqlite in android Failed to read row 0, column -1 from a CursorWindow which has 19 rows, 2 columns
body: <p>I am getting following error when insert data in <code>sqlite</code>. I searched all previous post i think code right. When first executed then worked correctly. but not working   </p>
  
  <pre><code> 01-28 11:56:51.209: E/AndroidRuntime(11292): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
  </code></pre>
  
  <p>// programmer code here</p>
  
  <pre><code>DBAdapter db = new DBAdapter(this);
  
  db.open();
  
  String allNumberText = "";
  
              Cursor cursor = db.getAllNumber();
  
              Log.d("First", "First");
  
              if( cursor.moveToFirst())
              {
                  Log.d("Run here", "Run here");
                  do{
                      Log.d("Second", "Second");
  
  
                      allNumberText += cursor.getString(cursor.getColumnIndex(KEY_PHONENUMBER));
  
  
                      Log.d("Third", "Third");
                      //allNumberText += " ";
                  }while(cursor.moveToNext());
              }
              cursor.close();
  
              displayNumber = (TextView) findViewById(R.id.displayNumber);
              displayNumber.setText(allNumberText);
  </code></pre>
  
  <p>// DBApter code is here</p>
  
  <p>public class DBAdapter {</p>
  
  <pre><code>static final String KEY_ROWID = "_ID";
  static final String KEY_PHONENUMBER = "phoneNumber";
  static final String TAG = "DBAdapter";
  
  static final String DATABASE_NAME = "PhoneNumberDB";
  static final String DATABASE_TABLE = "tableOfPhoneNumber";
  static final int    DATABASE_VERSION = 1;
  
  static final String DATABASE_CREATE = "CREATE TABLE " + DATABASE_TABLE + "(" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_PHONENUMBER + " TEXT NOT NULL);";
  
  
  final Context context;
  
  DatabaseHelper DBHelper;
  SQLiteDatabase db;
  
  public DBAdapter(Context ctx)
  {
      this.context = ctx;
      DBHelper = new DatabaseHelper(context);
  }
  
  private static class DatabaseHelper extends SQLiteOpenHelper
  {
      DatabaseHelper(Context context)
      {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
  
          db.execSQL(DATABASE_CREATE);
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
          db.execSQL("DROP TABLE IF EXITS DATABASE_NAME ");
          onCreate(db);
  
      }
  }
  
  // open database
  public DBAdapter open() throws SQLException
  {
      db = DBHelper.getWritableDatabase();
      return this;
  }
  
  // close database
  public void close()
  {
      DBHelper.close();
  }
  
  // insert phone number in database
  public long insertPhoneNumber(String phoneNumber)
  {
      ContentValues initialValues = new ContentValues();
      initialValues.put(KEY_PHONENUMBER, phoneNumber);
  
      return db.insert(DATABASE_TABLE, null, initialValues);
  }
  
  // delete a particular number
  public boolean deleteNumber(String phoneNumber)
  {
      return db.delete(DATABASE_TABLE, KEY_PHONENUMBER + "=" + phoneNumber, null) &gt; 0;
  }
  
  /*
  public boolean deleteNumber(String phoneNumber)
  {
      return db.delete(DATABASE_TABLE, KEY_PHONENUMBER + " = ?", new String[] {phoneNumber}) &gt; 0;
  }
  */
  
  // retrieves all the number
  public Cursor getAllNumber()
  {
      return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_PHONENUMBER}, null, null, null, null, null);
  }
  
  // retrieves a particular number
  public Cursor getNumber(String phoneNumber) throws SQLException
  {
      Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] { KEY_ROWID, KEY_PHONENUMBER} , KEY_PHONENUMBER + "=" +phoneNumber, null, null, null, null, null);
  
      if(mCursor != null)
      {
          mCursor.moveToFirst();
      }
  
      return mCursor;
  }
  </code></pre>
  
  <p>}</p>