android.database.StaleDataException: Attempted to access a cursor after it has been clos

今天在开发选择图片时发现有时候会报错:

 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>
这样上述问题就解决了,有时候版本不同确实会带来很多问题,开发过程中还是要小心为妙


根据你提供的信息,你遇到了一个Python相对路径导入的问题。具体报错信息是"ImportError: attempted relative import with no known parent package"。这个错误通常发生在使用相对导入时没有找到已知的父程序包。 解决这个问题的方法是,去掉"from ."导入,直接使用"import _convert"进行导入即可。这样就可以避免出现相对路径导入的问题。 希望我的回答对你有帮助。如果你有任何其他问题,请随时提问。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Python报错:ImportError: attempted relative import with no known parent package](https://blog.csdn.net/m0_45521766/article/details/126513067)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [ import _convert 报错 ImportError: attempted relative import with no known parent packageuan](https://blog.csdn.net/qq_43293247/article/details/127900587)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值