2013-07-08 57 views
0

我的數據已成功添加到database.i中,通過調試我的代碼進行檢查。但是當我使用遊標讀取該數據,它拋出以下異常: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.這裏是我的數據庫輔助函數代碼:在android中從sqlite數據庫通過光標讀取數據時出現異常

       `///get schools 
        public ArrayList<SchoolModel> getSchools() { 

         school.clear(); 

         SQLiteDatabase db = this.getReadableDatabase(); 
         Cursor cursor = db.rawQuery("select * from School", null); 
         if ((cursor.getCount() >0)){ 
          if (cursor.moveToFirst()) { 
           do { 
            SchoolModel item = new SchoolModel(); 
            item.SchoolID = cursor.getInt(cursor 
              .getColumnIndex("SchoolID ")); 
            item.Address= cursor.getString(cursor 
              .getColumnIndex("Address")); 
            item.Cell= cursor.getString(cursor 
              .getColumnIndex("Cell")); 
            item.ContactPerson= cursor.getString(cursor 
              .getColumnIndex("ContactPerson")); 
            item.Description= cursor.getString(cursor 
              .getColumnIndex("Description")); 
            item.Phone= cursor.getString(cursor 
              .getColumnIndex("Phone")); 
            item.AreaID = cursor.getInt(cursor 
              .getColumnIndex("AreaID")); 


            school.add(item); 

           } while (cursor.moveToNext()); 
          } 
         } 
         cursor.close(); 
         db.close(); 
         return school; 
        } 

誰能告訴我什麼我做錯了什麼?

回答

1
item.SchoolID = cursor.getInt(cursor .getColumnIndex("SchoolID ")); 

可能消除資本d後的枝條空間可以幫助

+0

三江源這麼多....它現在的工作:) –

+0

歡迎您。將答案標記爲已接受 – Blackbelt

相關問題