首頁  >  文章  >  資料庫  >  android.database.StaleDataException: Attempted to access a c

android.database.StaleDataException: Attempted to access a c

WBOY
WBOY原創
2016-06-07 15:50:001243瀏覽

10-17 15:08:53.084: E/AndroidRuntime(30153): FATAL EXCEPTION: main10-17 15:08:53.084: E/AndroidRuntime(30153): android.database.StaleDataException: Attempted to access a cursor after it has been closed.10-17 15:08:53.084: E/AndroidRuntime(

10-17 15:08:53.084: E/AndroidRuntime(30153): FATAL EXCEPTION: main10-17 15:08:53.084: E/AndroidRuntime(30153): android.database.StaleDataException: Attempted to access a cursor after it has been closed.10-17 15:08:53.084: E/AndroidRuntime(30153): at android.database.BulkCursorToCursorAdaptor.throwIfCursorIsClosed(BulkCursorToCursorAdaptor.java:64)10-17 15:08:53.084: E/AndroidRuntime(30153): at android.database.BulkCursorToCursorAdaptor.requery(BulkCursorToCursorAdaptor.java:133)10-17 15:08:53.084: E/AndroidRuntime(30153): at android.database.CursorWrapper.requery(CursorWrapper.java:186)10-17 15:08:53.084: E/AndroidRuntime(30153): at android.app.Activity.performRestart(Activity.java:5161)10-17 15:08:53.084: E/AndroidRuntime(30153): at android.app.ActivityThread.handleSleeping(ActivityThread.java:3280)10-17 15:08:53.084: E/AndroidRuntime(30153): at android.app.ActivityThread.access$2700(ActivityThread.java:141)10-17 15:08:53.084: E/AndroidRuntime(30153): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1413)10-17 15:08:53.084: E/AndroidRuntime(30153): at android.os.Handler.dispatchMessage(Handler.java:99)10-17 15:08:53.084: E/AndroidRuntime(30153): at android.os.Looper.loop(Looper.java:137)10-17 15:08:53.084: E/AndroidRuntime(30153): at android.app.ActivityThread.main(ActivityThread.java:5041)10-17 15:08:53.084: E/AndroidRuntime(30153): at java.lang.reflect.Method.invokeNative(Native Method)10-17 15:08:53.084: E/AndroidRuntime(30153): at java.lang.reflect.Method.invoke(Method.java:511)10-17 15:08:53.084: E/AndroidRuntime(30153): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)10-17 15:08:53.084: E/AndroidRuntime(30153): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)10-17 15:08:53.084: E/AndroidRuntime(30153): at dalvik.system.NativeStart.main(Native Method)

发生原因:

我在代码中使用了Context.managedQuery(),Cursor.close()方法,但是在android 4.0及其以上的版本中,Cursor会自动关闭,不需要用户自己关闭。

解决方法:

在Cursor.close()方法上加上

  1. if(VERSION.SDK_INT 14) {  
  2.     cursor.close();  
  3.  }  

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn