title: Exception while reading from SQLite DB in android
body: <p>I don't know the meaning of this error , anyone can help ?</p>
  
  <pre><code>10-15 13:07:02.221: DEBUG/query(587): SELECT event_id as _id,start_date, end_date, event_body, event_title, student_id, event_status, service_number, password, lecturer_id, fec_no, dept_no,floor_no from timetable
  10-15 13:07:02.231: ERROR/CursorWindow(587): Bad request for field slot 1,-1. numRows = 4, numColumns = 13
  10-15 13:07:02.231: DEBUG/AndroidRuntime(587): Shutting down VM
  10-15 13:07:02.231: WARN/dalvikvm(587): threadid=1: thread exiting with uncaught exception (group=0x40015560)
  </code></pre>
  
  <p>and ..</p>
  
  <pre><code>10-15 13:07:02.252: ERROR/AndroidRuntime(587): FATAL EXCEPTION: main
  10-15 13:07:02.252: ERROR/AndroidRuntime(587): java.lang.IllegalStateException: get field slot from row 1 col -1 failed
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at android.database.CursorWindow.getString_native(Native Method)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at android.database.CursorWindow.getString(CursorWindow.java:329)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at com.android.database.DatabaseHelper.getAllAppointments(DatabaseHelper.java:337)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at com.android.uis.DaysActivity.bindList(DaysActivity.java:80)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at com.android.uis.DaysActivity.access$2(DaysActivity.java:78)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at com.android.uis.DaysActivity$2.onClick(DaysActivity.java:67)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at android.view.View.performClick(View.java:2485)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at android.view.View$PerformClick.run(View.java:9080)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at android.os.Handler.handleCallback(Handler.java:587)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at android.os.Handler.dispatchMessage(Handler.java:92)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at android.os.Looper.loop(Looper.java:130)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at android.app.ActivityThread.main(ActivityThread.java:3683)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at java.lang.reflect.Method.invokeNative(Native Method)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at java.lang.reflect.Method.invoke(Method.java:507)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  10-15 13:07:02.252: ERROR/AndroidRuntime(587):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>this line of code that causes the problem ..</p>
  
  <pre><code>appointment.mStartDate = formatter.parse(c.getString(c.getColumnIndex("COL_START_DATE")));
  </code></pre>
  
  <h2>Edit</h2>
  
  <p>more code ..
  The function that retrieve from database </p>
  
  <pre><code>public ArrayList&lt;Appointment&gt; getAllAppointments(){
          ArrayList&lt;Appointment&gt; appointments = new ArrayList&lt;Appointment&gt;();
          Appointment appointment = null;
          SQLiteDatabase db = this.getWritableDatabase();
  
          String query = "SELECT "+
                  COL_EVENT_ID+ " as _id,"+
                  COL_START_DATE+", "+
                  COL_END_DATE+", "+
                  COL_EVENT_BODY+", "+
                  COL_EVENT_TITLE+", "+
                  COL_STUDENT_ID+", "+    
                  COL_EVENT_STATUS+", "+
                  COL_SERVICE_NUMBER+", "+
                  COL_PASSWORD+", "+
                  COL_LECTURER_ID+", "+       
                  COL_SEC_NO+", "+
                  COL_DEPT_NO+","+
                  COL_FLOOR_NO+" from "+TIMETABLE_TABLE;
  
          Cursor c = db.rawQuery(query,new String[]{});
          Log.d("query",query);
  
          c.moveToFirst();
          while(c.moveToNext()){
              appointment = new Appointment();
              try {
                  appointment.mEventId = c.getInt(c.getColumnIndex("_id"));
                  appointment.mStartDate = formatter.parse(c.getString(c.getColumnIndex("COL_START_DATE")));
                  appointment.mEndDate = formatter.parse(c.getString(c.getColumnIndex("COL_END_DATE")));
                  appointment.mBody = c.getString(c.getColumnIndex("COL_EVENT_BODY"));
                  appointment.mTitle = c.getString(c.getColumnIndex("COL_EVENT_TITLE"));
                  appointment.mStudentId = c.getString(c.getColumnIndex("COL_STUDENT_ID"));
                  appointment.mSatus = c.getInt(c.getColumnIndex("COL_EVENT_STATUS"));
                  appointment.mServiceNo = c.getInt(c.getColumnIndex("COL_SERVICE_NUMBER"));
                  appointment.mPassword = c.getString(c.getColumnIndex("COL_PASSWORD"));
                  appointment.mLecturerId = c.getInt(c.getColumnIndex("COL_LECTURER_ID"));
                  appointment.mSecNo = c.getInt(c.getColumnIndex("COL_SEC_NO"));
                  appointment.mDeptNo = c.getInt(c.getColumnIndex("COL_DEPT_NO"));
                  appointment.mFloorNo = c.getInt(c.getColumnIndex("COL_FLOOR_NO"));
              } catch (ParseException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              appointments.add(appointment);
          }
          db.close();
          return appointments;
      }
  </code></pre>
  
  <p>piece of code that create the table ..</p>
  
  <pre><code>db.execSQL("CREATE TABLE "+ TIMETABLE_TABLE+
                  " ("+COL_EVENT_ID+" TEXT PRIMARY KEY , "+
                  COL_START_DATE+ " TEXT , "+
                  COL_END_DATE+" TEXT , "+
                  COL_EVENT_BODY+" TEXT ,"+
                  COL_STUDENT_ID+ " TEXT , "+
                  COL_EVENT_TITLE+ " TEXT , "+
                  COL_EVENT_STATUS+" INTEGER ,"+
                  COL_SERVICE_NUMBER+ " INTEGER , "+
                  COL_PASSWORD+" TEXT , "+
                  COL_LECTURER_ID+" TEXT ,"+
                  COL_SEC_NO+ " INTEGER , "+
                  COL_DEPT_NO+" INTEGER , "+
                  COL_FLOOR_NO+" INTEGER "+");");
  </code></pre>