title: Make sure the Cursor is initialized correctly before accessing data from it. sql android
body: <pre><code>public class recordd extends Activity{
  
  
      Button b;
      int count;
      String date;
      Record record;
      SQLiteDatabase db;
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.record);
  
          int calo =getIntent().getIntExtra("cal", 0);
  
          TextView TEXT =(TextView)findViewById(R.id.record);
  
  
          record= new Record(this);
          db= record.getWritableDatabase();
          db.execSQL("INSERT INTO tab VALUES (null, 'calo' ,null);");
  
          Cursor cursor = db.rawQuery("SELECT SUM(cal) FROM tab ", null);
  
  
          while(cursor.moveToNext()){
              int addr = cursor.getInt(0);
              String addrrr = Integer.toString(addr);
              String abc = cursor.getString(2);
          }
  </code></pre>
  
  <p>i get the 'calo' from the last activity. and then put that number to the sql table which name is tab. and then make a cursor to sum the cal which has the information for the calo. 
  but there is a problem .</p>
  
  <blockquote>
    <p>"Caused by: java.lang.IllegalStateException: Couldn't read row 0, col
    2 from CursorWindow.  Make sure the Cursor is initialized correctly
    before accessing data from it."</p>
  </blockquote>
  
  <p>and this is the more information for the table creation. </p>
  
  <pre><code>public class Record extends SQLiteOpenHelper {
  
      static final String DATABASE_NAME = "mydb.db"; 
      static final int DATABASE_VERSION = 1; 
  
  
  
  
      public Record(Context context){
  
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
  
  
  
      @Override
  
      public void onCreate(SQLiteDatabase db) {
          db.execSQL("CREATE TABLE tab ( _id INTEGER PRIMARY KEY AUTOINCREMENT, "
                  +"cal INTEGER, timestamp DATE DEFAULT (datetime('now','localtime')));");
      }
  
      @Override 
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          db.execSQL("DROP TABLE IF EXISTS tab;");
          onCreate(db);
      }
  
  
  
  }
  </code></pre>
  
  <p>I have dumped for days</p>