“显式终止方法'关闭'没有被称为”什么意思?

时间:2014-03-04 04:56:09

标签: android android-sqlite sqliteopenhelper

  

03-02 04:23:07.015:E / StrictMode(1096):在附加的堆栈跟踪处获取资源但从未释放。有关避免资源泄漏的信息,请参阅java.io.Closeable。   03-02 04:23:07.015:E / StrictMode(1096):java.lang.Throwable:未调用显式终止方法'close'   03-02 04:23:07.015:E / StrictMode(1096):at dalvik.system.CloseGuard.open(CloseGuard.java:184)   03-02 04:23:07.015:E / StrictMode(1096):在android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:805)   03-02 04:23:07.015:E / StrictMode(1096):在android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)   03-02 04:23:07.015:E / StrictMode(1096):在android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)   03-02 04:23:07.015:E / StrictMode(1096):在android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:944)   03-02 04:23:07.015:E / StrictMode(1096):在android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)   03-02 04:23:07.015:E / StrictMode(1096):在android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)   03-02 04:23:07.015:E / StrictMode(1096):at com.helper.database.DBOperator.queryfeeds(DBOperator.java:53)   03-02 04:23:07.015:E / StrictMode(1096):at com.example.rssreader.MainActivitySpace.getfeeddata(MainActivitySpace.java:85)   03-02 04:23:07.015:E / StrictMode(1096):at com.example.rssreader.MainActivitySpace.onActivityCreated(MainActivitySpace.java:74)   03-02 04:23:07.015:E / StrictMode(1096):在android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1508)   03-02 04:23:07.015:E / StrictMode(1096):在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)   03-02 04:23:07.015:E / StrictMode(1096):在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)   03-02 04:23:07.015:E / StrictMode(1096):在android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)   03-02 04:23:07.015:E / StrictMode(1096):在android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)   03-02 04:23:07.015:E / StrictMode(1096):在android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)   03-02 04:23:07.015:E / StrictMode(1096):在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)   03-02 04:23:07.015:E / StrictMode(1096):在android.app.Activity.performStart(Activity.java:5253)   03-02 04:23:07.015:E / StrictMode(1096):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2149)   03-02 04:23:07.015:E / StrictMode(1096):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)   03-02 04:23:07.015:E / StrictMode(1096):在android.app.ActivityThread.access $ 700(ActivityThread.java:135)   03-02 04:23:07.015:E / StrictMode(1096):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1397)   03-02 04:23:07.015:E / StrictMode(1096):在android.os.Handler.dispatchMessage(Handler.java:102)   03-02 04:23:07.015:E / StrictMode(1096):在android.os.Looper.loop(Looper.java:137)   03-02 04:23:07.015:E / StrictMode(1096):在android.app.ActivityThread.main(ActivityThread.java:4998)   03-02 04:23:07.015:E / StrictMode(1096):at java.lang.reflect.Method.invokeNative(Native Method)   03-02 04:23:07.015:E / StrictMode(1096):at java.lang.reflect.Method.invoke(Method.java:515)   03-02 04:23:07.015:E / StrictMode(1096):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:777)   03-02 04:23:07.015:E / StrictMode(1096):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)   03-02 04:23:07.015:E / StrictMode(1096):at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

在光标超出范围之前,您需要在光标上显式调用close。如果你不这样做游标的内容,那么它的分配资源将被释放,直到垃圾收集器决定实际删除它。 由于光标需要大量资源,所以一旦不再使用它就立即关闭它。