android.database.StaleDataException: Attempted to access a cursor after it has been clos
2014-06-11 10:19
330 查看
今天在开发选择图片时发现有时候会报错:
Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
手机是android版本是4.2.1
网上查找了一下发现是由于android版本的问题,4.0以上会自动关闭游标,不需要手动关闭,故再进行手动关闭的时候就报出了以上异常
修改前的代码:
Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been closed.
手机是android版本是4.2.1
网上查找了一下发现是由于android版本的问题,4.0以上会自动关闭游标,不需要手动关闭,故再进行手动关闭的时候就报出了以上异常
修改前的代码:
<span style="font-size:18px;"> String[] pojo = {MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery(photoUri, pojo, null, null,null); String picPath=null; if(cursor != null ) { int columnIndex = cursor.getColumnIndexOrThrow(pojo[0]); cursor.moveToFirst(); picPath = cursor.getString(columnIndex); cursor.close(); } </span>
<span style="font-size:18px;"> String[] pojo = {MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery(photoUri, pojo, null, null,null); String picPath=null; if(cursor != null ) { int columnIndex = cursor.getColumnIndexOrThrow(pojo[0]); cursor.moveToFirst(); picPath = cursor.getString(columnIndex); try { //4.0以上的版本会自动关闭 (4.0--14;; 4.0.3--15) if(Integer.parseInt(Build.VERSION.SDK) < 14) { //只有4.0以下才需要手动关闭 cursor.close(); } }catch(Exception e) { CommonHelper.log(TAG+":addPhoto",e.getMessage()); } } </span>这样上述问题就解决了,有时候版本不同确实会带来很多问题,开发过程中还是要小心为妙
相关文章推荐
- android.database.StaleDataException: Attempted to access a cursor after it has been closed.
- Caused by: android.database.StaleDataException: Attempted to access a cursor after it has been close
- 异常:android.database.StaleDataException: Attempted to access a cursor after it has been closed
- android.database.StaleDataException: Attempted to access a cursor after it has been closed
- android.database.StaleDataException: Attempted to access a cursor after it has been closed
- android.database.StaleDataException: Attempted to access a cursor after it has b
- Android报错 Attempted to access a cursor after it has been closed.的解决方法
- Android读取相册时报错:Attempted to access a cursor after it has been closed.
- android开发问题:Attempted to access a cursor after it has been closed.
- Attempted to access a cursor after it has been closed 的问题
- Unable to resume activity : android.database.StaleDataException: Attempted to access a cursor after it has been closed. 异常
- This app has crashed because it attempted to access privacy-sensitive data without a usage descripti
- This app has crashed because it attempted to access privacy-sensitive data without a usage descripti
- This app has crashed because it attempted to access privacy-sensitive data without a usage descripti
- The connection pool for database '/data/data/....db' has been unable to grant a connection to thread
- Xcode8使用出现This app has attempted to access privacy-sensitive data without a usage description.
- android中Warning: Activity not started, its current task has been brought to the front是什么错误
- The object of type 'RectTransform' has been destroyed but you are still trying to access it
- android.database.StaleDataException
- Android异常总结---ActivityManager: Warning: Activity not started,its current task has been brought to th