我已經越來越此異常,DatabaseObjectNotClosedException:如何解決這個異常?
close() was never explicitly called on database '/data/data/com.project.test/databases/database'
E/SQLiteDatabase(13921): android.database.sqlite.DatabaseObjectNotClosedException:
Application did not close the cursor or database object that was opened here
我試圖關閉數據庫助手和遊標,但我會得到運行時異常。當我離開活動並在點擊後退按鈕後重新訪問它時,會發生這種情況。
如何正確關閉我的遊標和助手?
我已經嘗試了兩種方法:
首先,關閉遊標每一個人使用後,在onPause和關閉數據庫幫手。
秒,隨着數據庫幫助關閉遊標onpause,但都沒有奏效。
有人可以幫助我嗎?
編輯:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = this.getActivity();
context = this.getActivity().getApplicationContext();
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mDbHelper = new DatabaseHelper(context);
mDbHelper.open();
populateList();
}
public void populateList() {
directoryCursor = mDbHelper.fetchAllRootDirectories();
activity.startManagingCursor(directoryCursor);
adapter = new DirectoryListAdapter(this.getActivity(), directoryCursor);
this.setListAdapter(adapter);
}
......
private UpdateDatabaseListener updateDatabaseListener = new UpdateDatabaseListener() {
public void onUpdate(int from, int to) {
.....
findExistingRecordCursor = mDbHelper.findExistingRecords(from, to);
activity.startManagingCursor(findExistingRecordCursor);
if(findExistingRecordCursor.getCount() == 0) {
....
}
}
}
我在OnCreate()函數打開的數據庫幫手。 填充列表視圖時使用的遊標, 用於查找現有記錄的遊標, 遊標以獲取信息。
UPDATE:
我試圖關閉的onPause和的onDestroy,但它仍然與RuntimeException的崩潰。
能否請您發佈您的代碼 – Gaurav
@Gaurav這部分的代碼,你真正需要看到的?因爲它確實有很多代碼。我可以看到我可以粘貼什麼。 –
@Gaurav我寫下我在那裏用databasehelper和遊標 –