title: Make sure the Cursor is initialized correctly before accessing
body: <p>I use next code to play with a temporary SQLite table:</p>
  
  <pre><code>public class DBHelperForTemp extends SQLiteOpenHelper {
  
  private final static String DB_NAME = "tempdb";
  private final static int DB_VERSION = 3;
  
  public DBHelperForTemp(Context context) {
      super(context, DB_NAME, null, DB_VERSION);
  }
  
  @Override
  public void onCreate(SQLiteDatabase db) {
      String createTable = "CREATE TABLE tbl ( ID INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, image BLOB )";
      db.execSQL(createTable);
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS tbl");
      onCreate(db);
  }
  
  public boolean add_Temp_Values(String name, byte[] image) throws SQLiteException {
      SQLiteDatabase db = this.getWritableDatabase();
  
      ContentValues contentValues = new ContentValues();
      contentValues.put("name", name);
      contentValues.put("image", image);
  
      long result = db.insert("tbl", null, contentValues);
  
      return result != -1;
  }
  
  
  public Cursor get_Data(){
      SQLiteDatabase db = this.getWritableDatabase();
      String query = "SELECT * FROM tbl";
      return db.rawQuery(query, null);
  }
  
  
  public void ClearData(){
      SQLiteDatabase db = this.getWritableDatabase();
      db.execSQL("delete from tbl");
  }
  
  }
  </code></pre>
  
  <p>save data to temp:</p>
  
  <pre><code>private void  doTemp(){
      final Bitmap photo = ((BitmapDrawable) mPhotoImageView.getDrawable()).getBitmap();
      boolean insertData = mDBTemp.add_Temp_POI_Values(mNameEditText.getText().toString(),
             Utils.imageToByteArray(photo) );
      if (insertData){
          Toast.makeText(this, R.string.fb_success, Toast.LENGTH_SHORT).show();
      } else {
          Toast.makeText(this, R.string.fb_error, Toast.LENGTH_SHORT).show();
      }
      finish();
  }
  </code></pre>
  
  <p>and try to read from temp and send to firebase with:</p>
  
  <pre><code>private void onSubmit(){
      final DBHelperForTemp mDBTemp = new DBHelperForTemp(this);
      final Cursor data = mDBTemp.get_Data();
      if (data != null &amp;&amp; data.getCount() != 0 &amp;&amp; data.moveToFirst()){
          for (int i = 0; i &lt; data.getCount(); i++) {
              final String name = data.getString(data.getColumnIndex("name"));
              final byte[] byteArray = data.getBlob(data.getColumnIndex("image"));
              final Bitmap photo = BitmapFactory.decodeByteArray(byteArray, 0 , byteArray.length);
  .........
  </code></pre>
  
  <p>I get next error code when try to use it:</p>
  
  <pre><code>E/UncaughtException: java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
                                                                                           at android.database.CursorWindow.nativeGetString(Native Method)
                                                                                           at android.database.CursorWindow.getString(CursorWindow.java:451)
                                                                                           at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
                                                                                           at com.test.test.activities.ActivityMain.onSubmit
  </code></pre>
  
  <p>What is interesting is that code work if I don't have an image in temporary table. If have an image the app crash but there where try to read the name string and not image.</p>
  
  <p>Anyone can help me to detect problem? </p>
  
  <p>data.getCount() return 1. data.getColumnIndex("name") return 0. data.getString(0) return Method threw 'java.lang.IllegalStateException' exception. Couldn't read row 0, col 1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.</p>