Attempted to access a cursor after it has been clo
Recommended for you: Get network issues from WhatsUp Gold. Not end users.
[html]
- android.database.StaleDataException: Attempted to access a cursor after it has been closed.
- at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2444)
- at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
- at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1173)
- at android.os.Handler.dispatchMessage(Handler.java:99)
- at android.os.Looper.loop(Looper.java:137)
- at android.app.ActivityThread.main(ActivityThread.java:4424)
- at java.lang.reflect.Method.invokeNative(Native Method)
- at java.lang.reflect.Method.invoke(Method.java:511)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
- at dalvik.system.NativeStart.main(Native Method)
- Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
Select a picture after the code in onActivityResult is as follows:
[java]
- Uri uri = data.getData();
- if (uri != null)
- {
- mFilePath = new URIUtils().getPathFromUri(uri);
- }
The solution as shown in note. More than 4 platform will automatically shut down cursor
[java]
- protected String getPath(Uri uri)
- {
- String filePath = "";
- String[] projection = {MediaColumns.DATA };
- Cursor cursor = managedQuery(uri,
- projection,
- null,
- null,
- null);
- if (cursor != null)
- {
- int columnIndex = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
- cursor.moveToFirst();
- filePath = cursor.getString(columnIndex);
- try
- {
- //Version 4 and above will automatically shut down (4.0--14;; 4.0.3--15)
- if(Integer.parseInt(Build.VERSION.SDK) < 14)
- {
- cursor.close();
- }
- }catch(Exception e)
- {
- Log.error(TAG, "error:" + e);
- }
- }
- return filePath;
- }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download
Posted by Morgan at February 21, 2014 - 3:38 AM