`
ericliu1986
  • 浏览: 111224 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

Application did not close the cursor or database object that was opened here

阅读更多

        这两天调试程序的时候,发现LogCat里时不时的会打出"DatabaseObjectNotClosedException"这个异常,异常的详细堆栈信息如下:

 

close() was never explicitly called on database '/data/data/cn.eric.sqlitedbdemo/databases/people.db'
android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
    at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1827)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
    at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
    at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
    at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:541)
    at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
    at cn.eric.sqlitedbdemo.SQLiteDatabaseHelper.query(SQLiteDatabaseHelper.java:61)
    at cn.eric.sqlitedbdemo.SQLiteDatabaseDemo$1$1.run(SQLiteDatabaseDemo.java:53)

 

但是这个异常的抛出并没有让程序崩溃。

    这些异常信息来源于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时,就会打出以上的信息。

    @Override
    protected void finalize() {
        if (isOpen()) {
            Log.e(TAG, "close() was never explicitly called on database '" +
                    mPath + "' ", mStackTrace);
            closeClosable();
            onAllReferencesReleased();
        }
    }

 

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

分享到:
评论
3 楼 banxi1988 2012-09-01  
此博客对我有用!
2 楼 txin0814 2011-09-30  
yangxue00 写道
弱弱的问一下,红色字体部分是你从logcat中复制过来的吗??怎么复制啊?

兄弟 选中 ctrl+c不就可以COPY了吗
1 楼 yangxue00 2011-08-18  
弱弱的问一下,红色字体部分是你从logcat中复制过来的吗??怎么复制啊?

相关推荐

    mysql安装失败

    If you are re-installing after you just uninstalled the MySQL server please note that the data directory was not removed automatically. Therefore the old password from your last installation is still ...

    jacob Hiding the application window is not allowed

    设置隐试打开PPT报错 Hiding the application window is not allowed

    数位板压力测试

    The device must have a point-ing ap¬para¬tus or method (such as a stylus, or a finger touching a touch pad), called the cursor, that de¬fines the current position. The cursor must be able to ...

    端口查看工具

    the process that opened the ports, and save the TCP/UDP ports information to HTML file , XML file, or to tab-delimited text file. CurrPorts also automatically mark with pink color suspicious TCP/UDP ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: The TFlexPanel.FindControlAtPoint method maked virtual to realize RealTime-capability when on mouse cursor moving the flex-object search not occurs. - FIX: After deleting the selected points ...

    Oracle Database 12c Release 2 Real Application Clusters Handbook

    Oracle Database 12c Release 2 Real Application Clusters Handbook: Concepts, Administration, Tuning, and Troubleshooting has been thoroughly revised and updated to cover the latest tools and features....

    VclZip pro v3.10.1

    VCLZip Native Delphi Zip/UnZip Component!...Fixed a problem that was not allowing ZipComment's to be added correctly to spanned or blocked zip files. Not the same fix as in 2.22. Directories ...

    Expert Oracle Database Architecture 2nd 原版PDF by Kyte

    I covered what I felt was most relevant, namely the Oracle database and its architecture. I could have written a similarly titled book explaining how to develop an application using a specific ...

    Designing Object-Oriented C++ Applications-Using the Booch Method

    A practical, problem-solving approach to the fundamental concepts of Object Oriented Design and their application using C++. This book is written for the "engineer in the trenches". It is a serious ...

    微软内部资料-SQL性能优化3

    However, the req_mode column of master.dbo.syslockinfo has lock mode code that is one less than the code values shown here. For example, value of req_mode = 3 represents the Shared lock mode rather ...

    developing android application with adobe air.part3.rar

    Rendering, or How Things Are Drawn to the Screen GPU Rendering on Android The Display List Matrices Hardware-Accelerated Audio and Video Conclusion Chapter 15 : Your Device and Others RTMFP UDP P2P ...

    Universal-USB-Installer

    gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know ...

    [Google 论文] F1: A Distributed SQL Database That Scales

    F1 is a hybrid database that combines high availability, the scalability of NoSQL systems like Bigtable, and the consistency and us- ability of traditional SQL databases. F1 is built on Span- ner, ...

    曲线拟合工具CurveExpert 1.0

    ct. 18, 1995 v. 1.00 =========================================================================== + First release of ... + The user was still asked whether to save a file or not upon exiting, even if ...

    Object Tracking A Survey

    Tracking is usually performed in the context of higher-level applications that require the location and/or shape of the object in every frame. Typically,assumptions are made to constrain the tracking...

    WizFlow网页编辑

    in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a ...

    hibernate-shards.jar

    in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a ...

    计算机网络第六版答案

    An ISP earns its money by charging each of the the ISPs that connect to the IXP a relatively small fee, which may depend on the amount of traffic sent to or received from the IXP. 15. Google's ...

    Senfore_DragDrop_v4.1

    "Ignore All" when the IDE complains that this or that property doesn't exist and finally save the forms. ------------------------------------------- 3. Getting started: -----------------------------...

Global site tag (gtag.js) - Google Analytics