0

I am try to pick an image from gallery and set in image view in FRAGMENT. But I am getting the value of picture path perfectly but i am unable to get value bitmap(It gives null value). Note:The main problem is bitmap giving null value and not Nullpointer exception.

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);

Here is my 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
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Harshad Pansuriya Jul 20 '16 at 11:48
  • The `decodeFile()` method will return null if the bitmap could not be decoded. It could be a wrong path, an unmounted storage or a too large bitmap..... – Opiatefuchs Jul 20 '16 at 11:48
  • @Ironman I don´t agree with your statement because the questioner knows that bitmap is null. It´s not the exception is wondering about, she/he wants to know the reason why decodeFile() returns null..... – Opiatefuchs Jul 20 '16 at 11:50
  • But this code is working in activity perfectly.Wheras this problem arises while working with Fragments.any clue? – Vikas Anand Jul 20 '16 at 11:51
  • so you should post the error stacktrace... – Opiatefuchs Jul 20 '16 at 11:52
  • You should put that info directly in your post. Not in a comment. – greenapps Jul 20 '16 at 11:52
  • `I am getting the value of picture path perfectly `. Please tell what you get. – greenapps Jul 20 '16 at 11:54
  • @VikasAnand why didt you show your logact? please add it. – Sohail Zahid Jul 20 '16 at 11:55
  • /storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20160706-WA0031.jpg – Vikas Anand Jul 20 '16 at 11:56
  • Which statement causes a NulPointerException? Show the LogCat. If you get a correct path then the rest of your code will not produce a NullPointerException. So what is going on? – greenapps Jul 20 '16 at 11:56
  • `(It gives null value).`. But that is something different as a NullPointerException. What is going on? Post the LogCat!!!! – greenapps Jul 20 '16 at 11:58
  • 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 – Vikas Anand Jul 20 '16 at 12:02
  • Do not post that in a comment. Post it in your text in a new block. And post more of that LogCat to be of use. And a bitmap that is null is not equal to a NullPointerException! Please clarify! That exception should be mentioned in the LocCat. So start with that! – greenapps Jul 20 '16 at 12:04
  • Improved the question just now. – Vikas Anand Jul 20 '16 at 12:11
  • If the bitmap is null then read the second comment again. There is the answer. You gave us a lot of work helping you and you can only say 'improved'. You need to request read external storage permission too. – greenapps Jul 20 '16 at 12:30
  • `Bitmap giving null value´. No `BitmapFactory.decodeFile()` returns null. – greenapps Jul 20 '16 at 12:35
  • Please give a logical answer if you know it.Dont ponder over how the question was asked or how it was improved.You are answering everything except for the helping answer which you are supposed to do.Dont waste my time and time of other people. @greenapps – Vikas Anand Jul 21 '16 at 06:47

0 Answers0