android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or da

来源:互联网 发布:direct是什么软件 编辑:程序博客网 时间:2024/05/16 18:50
这个异常的抛出并没有让程序崩溃。

    这些异常信息来源于SQLiteDatabase类的finalize方法。从异常的信息"close() was never explicitly called on database ,Application did not close the cursor or database object that was opened here
"可以知道这是由于程序中使用到的游标或SQLiteDatabase对象没有close所导致。也就是说在程序中创建的Cursor对象或者SQLiteDatabase对象,在使用完后没有关闭,而当它们都变成“垃圾"被GC时,就会打出以上的信息。

Java代码 
  1. @Override 
  2. protected void finalize() { 
  3.     if (isOpen()) { 
  4.         Log.e(TAG, "close() was never explicitly called on database '"
  5.                 mPath + "' ", mStackTrace); 
  6.         closeClosable(); 
  7.         onAllReferencesReleased(); 
  8.     } 

    所以要想不发生这样的错误,在编码时一定要记住,当你不在使用Cursor或SQLiteDatabase对象时,将它们close(),

原创粉丝点击