2012-09-04 2 views
0

전에 문제를 해결하기 위해 주변을 둘러 보았으므로 직접 해결할 수 없으므로 사용자에게 전달됩니다.SQLIte 커서가 비활성화되거나 닫히지 않은 null에서 완료 예외적 인 경우

인한 문제

내 커서 캐치되지 않는 예외 문제가 내가 그것을 밖으로 작동하지 않을 수 있습니다 ....

ERROR 자사의 불평

09-04 15:48:38.863: I/dalvikvm(1421): Uncaught exception thrown by finalizer (will be discarded): 
09-04 15:48:38.863: I/dalvikvm(1421): Ljava/lang/IllegalStateException;: Finalizing cursor [email protected] on null that has not been deactivated or closed 
09-04 15:48:38.863: I/dalvikvm(1421): at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596) 
09-04 15:48:38.873: I/dalvikvm(1421): at dalvik.system.NativeStart.run(Native Method) 

코드를 회사 소개

public CCTrackLocation getTrackLocationForID(int id) { 
     CCTrackLocation trackLocation = new CCTrackLocation(); 

     String selectQuery = "SELECT * FROM "+TABLE_TRACK_LOCATION+" WHERE \"id\" = "+ String.valueOf(id); 

     SQLiteDatabase db = this.getReadableDatabase(); 
     Cursor cursor = db.rawQuery(selectQuery,null); 
     if (cursor.moveToFirst()) { 
      do { 
       trackLocation.setID(cursor.getInt(0)); 
       trackLocation.segmentID = cursor.getInt(1); 
       trackLocation.timestamp = cursor.getDouble(2); 
       trackLocation.latitude = cursor.getDouble(3); 
       trackLocation.longitude = cursor.getDouble(4); 
       trackLocation.altitude = cursor.getDouble(5); 
       trackLocation.velocity = cursor.getDouble(6); 
       trackLocation.heading = cursor.getDouble(7); 
       trackLocation.haccuracy = cursor.getDouble(8); 
       trackLocation.vaccuracy = cursor.getDouble(9); 
      }while(cursor.moveToNext()); 
     } 

     cursor.close(); 
     db.close(); 

     return trackLocation; 
    } 

도움을 주시면 대단히 감사하겠습니다.

답변

0

여기에서이 문제를 해결하기 위해 내가 한 일이 있습니다.

  1. 데이터베이스를 한 번만 열었다 닫았습니다. 내가 데이터베이스를 열 때마다 데이터베이스를 닫았지만 때로는 충분히 빠르지 않아서 오류가 발생했습니다.
  2. 매번 사용 후 커서가 닫히고 끝났습니다. 이것은 문제를 분류했다.
0

try/catch/finally 절 안에 모든 db 코드를 넣고 cursor.close() 및 db.close()를 마침내 이동하여 닫는 지 확인하십시오 예외가 던져 지더라도 커서와 데이터베이스.

관련 문제