-1

我的整个应用程序运行良好,但是当我看到 logcat 时,我可以看到这些错误消息,例如即使在我使用语句 MyDBinstance.close() 关闭数据库之后,数据库也没有关闭。为什么它们又来了?,它们对我的应用程序有害吗?

 11-23 23:09:03.593: E/SQLiteDatabase(30762): close() was never explicitly called on  database '/data/data/dlp.android.digichronicle/databases/widget.sqlite' 
 11-23 23:09:03.593: E/SQLiteDatabase(30762): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1943)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at  android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1007)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:962)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at dlp.android.digichronicle.DBHandandler.openDataBase(DBHandandler.java:117)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at dlp.android.digichronicle.inter.FetchingData(inter.java:95)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at dlp.android.digichronicle.inter.onCreate(inter.java:29)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.app.Activity.performCreate(Activity.java:4465)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.app.ActivityThread.access$600(ActivityThread.java:123)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.os.Handler.dispatchMessage(Handler.java:99)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at  android.os.Looper.loop(Looper.java:137)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at android.app.ActivityThread.main(ActivityThread.java:4424)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at  java.lang.reflect.Method.invokeNative(Native Method)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at java.lang.reflect.Method.invoke(Method.java:511)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
 11-23 23:09:03.593: E/SQLiteDatabase(30762):   at dalvik.system.NativeStart.main(Native Method)
 11-23 23:09:03.752: I/dalvikvm(30762): threadid=3: reacting to signal 3
 11-23 23:09:03.811: I/dalvikvm(30762): Wrote stack traces to '/data/anr/traces.txt'
 11-23 23:09:16.182: I/System.out(30762): got from accounts1.0exp1.0
 11-23 23:09:16.332: I/System.out(30762): Bundle[mParcelledData.dataSize=52]
4

2 回答 2

2

您可能希望这样做以确保始终关闭光标:

Cursor c = null;
try   {

   c  = somehowCreateACursor();

} finally {

    if(c != null) {
        c.close();
    }

}
于 2012-11-23T17:58:25.520 回答
0

实际上没有必要关闭数据库。即使会产生上述异常,但它永远不会以任何方式损害应用程序。

于 2012-11-23T18:28:01.643 回答