为了账号安全,请及时绑定邮箱和手机立即绑定

android真机测试时获取系统图片的Cursor老是空指针异常,怎么解?

android真机测试时获取系统图片的Cursor老是空指针异常,怎么解?

慕九州4544299 2016-06-08 20:02:40
android真机测试时获取系统图片的Cursor老是空指针异常,怎么解?手机用的是米4,android 6.0。可以打开图库,选择图片后返回出现空指针异常,cursor为空。Cursor cursor = act.getContentResolver().query(uri, projection, null, null, null);uri和projection都有值,模拟器测试正常。public void changePic(View view){    Intent intent=new Intent();     intent.setType("image/*");     intent.setAction(Intent.ACTION_GET_CONTENT);     startActivityForResult(intent, 1); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {     super.onActivityResult(requestCode, resultCode, data);     if(resultCode == RESULT_OK){         String fileName = null;         if(requestCode==1 && resultCode==RESULT_OK && null!=data){             Uri selectedImage=data.getData();             String[] filePathColumn={MediaStore.Images.Media.DATA};             Cursor cursor=getContentResolver().query(selectedImage, filePathColumn, null, null, null);             cursor.moveToFirst();//空指针异常,selectedImage, filePathColumn两个参数都有值             int columnIndex=cursor.getColumnIndex(filePathColumn[0]);             String picturePath=cursor.getString(columnIndex);             cursor.close();             PictrueConfig pic=new PictrueConfig();             Bitmap bitmap=pic.compressImageFromFile(fileName);             Date date = new Date(System.currentTimeMillis());             String dateTime = date.getTime() + "";             shopPic="pic"+dateTime+"_11.jpg";             fileName=pic.saveToSdCard(bitmap, dateTime, ShopManaActivity.this);             shopImage.setImageBitmap(BitmapFactory.decodeFile(picturePath));             targeturl = fileName; } } }
查看完整描述

1 回答

?
Genment

TA贡献43条经验 获得超25个赞

希望能多提供一点代码,以及相关log。

查看完整回答
反对 回复 2016-06-09
  • 1 回答
  • 0 关注
  • 1911 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信