Home  >  Article  >  Database  >  android.database.StaleDataException: Attempted to access a c

android.database.StaleDataException: Attempted to access a c

WBOY
WBOYOriginal
2016-06-07 15:50:001225browse

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.  }  

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn