>  기사  >  데이터 베이스  >  android.database.StaleDataException: Attempted to access a c

android.database.StaleDataException: Attempted to access a c

WBOY
WBOY원래의
2016-06-07 15:50:001221검색

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으로 문의하세요.