2017-05-01 1 views
1

현재 다트 계산기 응용 프로그램 인 대학 프로젝트에서 작업 중이며 모든 데이터베이스와 커서를 사용한 후에 닫는다고 생각하더라도 계속 데이터베이스 누출 오류가 발생합니다. 나는 또한 "W/IdleConnectionHandler : 절대 존재하지 않는 연결 제거!" 오류가 프로그램 시작 부분에 표시됩니다.내 응용 프로그램이 계속 충돌합니다. SQLite 데이터베이스 누출 오류

05-01 08:33:47.801 9504-9581/? W/IdleConnectionHandler: Removing a connection that never existed! 
05-01 08:43:46.141 9504-9581/? W/IdleConnectionHandler: Removing a connection that never existed! 

과 :

내 로그 캣은 이러한 오류가

05-01 09:08:06.841 4858-4866/? W/SQLiteConnectionPool: A SQLiteConnection object for database '+data+user+0+com_google_android_gms+databases+auto_complete_suggestions_db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed. 
05-01 09:08:06.841 4858-4866/? W/SQLiteConnectionPool: A SQLiteConnection object for database '+data+user+0+com_google_android_gms+databases+help_responses_db_18' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed. 
05-01 09:08:06.841 4858-4866/? W/SQLiteConnectionPool: A SQLiteConnection object for database '+data+user+0+com_google_android_gms+databases+metrics_db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed. 

내 데이터베이스 헬퍼 클래스는 다음과 같습니다

package com.dartsapp.niall.darts_calculator_cs2048; 

import android.content.Context; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 

public class DatabaseHelper extends SQLiteOpenHelper { 

private static final String database_name = "finishes.db"; 
private static final String table_name = "finishes_table"; 
//private static final String column1 = "score"; 
//private static final String column2 = "finish"; 
private static DatabaseHelper sInstance = null; 

public static DatabaseHelper getInstance(Context context) { 

    if (sInstance == null) { 
     sInstance = new DatabaseHelper(context.getApplicationContext()); 
    } 
    return sInstance; 
} 


private DatabaseHelper(Context context) { 
    super(context, database_name, null, 1); 
    //SQLiteDatabase db = this.getWritableDatabase(); 
    //db.close(); 
} 

public Cursor getData(int playerScore) { 
    SQLiteDatabase db = this.getWritableDatabase(); 
    Cursor res = db.rawQuery("select FINISH from "+table_name+" where SCORE = "+ playerScore,null); 
    res.close(); 
    db.close(); 
    return res; 
} 

@Override 
public void onCreate(SQLiteDatabase db) { 
    db.execSQL("CREATE TABLE IF NOT EXISTS "+table_name+ "(SCORE INTEGER, FINISH INTEGER)"); 
    String finish2 = 
      "INSERT or replace INTO tbl_Contain (SCORE, FINISH) VALUES('2','D1')" ; 
    db.execSQL(finish2); 

// LONG list of INSERTs - OMITTED 

    String finish170 = 
      "INSERT or replace INTO tbl_Contain (SCORE, FINISH) VALUES('170', 'T20 T20 BULL')" ; 
    db.execSQL(finish170); 
    db.close(); 
} 

@Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
    db.execSQL("DROP TABLE IF EXISTS " + table_name); 
    onCreate(db); 
    db.close(); 
} 

} 

내가 지금 어떤 여기에 심각한 시간 압력이다 도와 주시면 대단히 감사하겠습니다. '

+0

을 닫을 수 있습니다 가까운

res.moveToFirst(); //move Cursor to first record while (cur.isAfterLast() == false) { // while Cursor not point to last record Log.v("YOURTAG", cur.getString("yourString")); // get your data //ToDo save your data cur.moveToNext(); } // ToDo return your data 

커서 전에 코드에 이것을 추가해야합니다. 발신자가 그것을 소비 한 후에 그것을 닫도록하십시오. –

+1

onCreate –

+0

에 대한 쿼리를 실행 한 이유 데이터가 생성되는 즉시 데이터베이스에 넣기를 원했기 때문에 안드로이드 스튜디오에서 경험이 없으므로 이것이 정확한지 아닌지 확실하지 않습니다. 데이터를 삽입하는 더 좋은 방법이 있습니까? – nialln1

답변

0

레코드를 받기 전에 커서를 닫았습니다.

당신은 지금 당신이 호출자에게 반환하는 것을 의미한다면 당신은 당신의 커서를 닫을 수 없습니다 커서

관련 문제