位图在Android片段中给出null值

时间:2016-07-20 11:45:04

标签: android bitmap nullpointerexception null

我尝试从图库中选择图像并在FRAGMENT中的图像视图中设置。 但我完全得到了图片路径的值,但我无法获得值位图(它给出了空值)。 注意:主要问题是位图给出空值而不是Nullpointer异常。

Intent i = new Intent(
                Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);      

startActivityForResult(i, RESULT_LOAD_IMAGE);

public void onActivityResult(int requestCode, int resultCode, Intent data) {
       Uri selectedImage = data.getData();
       String[] filePathColumn = { MediaStore.Images.Media.DATA };

      Cursor cursor = getActivity().getContentResolver().query(selectedImage,
                        filePathColumn, null, null, null);
      cursor.moveToFirst();         int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String picturePath = cursor.getString(columnIndex);

       cursor.close();
       Bitmap b= BitmapFactory.decodeFile(picturePath);

这是我的logcat:

> 07-20 17:28:02.832 24228-24228/com.hello42 I/personal details: hello
> cursor android.content.ContentResolver$CursorWrapperInner@ee7b2c5
> 07-20 17:28:02.832 24228-24228/com.hello42 I/personal details: hello
> -- picturepath /storage/emulated/0/DCIM/Camera/IMG_20160716_155012_1.jpg 0 07-20
> 17:28:02.837 24228-24228/com.hello42 I/personal details: hello --
> bitmap null

0 个答案:

没有答案