0

I am facing with the NullpointerExcetion while putting image in Bitmap. I am getting Image from SD card.

        Uri path = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    imageFile = new File(getRealPathFromURI(path));
    if(imageFile.exists()){

        Bitmap myBitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());

        ImageView myImage = (ImageView) findViewById(R.id.imageView1);
        myImage.setImageBitmap(myBitmap);

    }
3
  • Since your code does not check for nulls, could you tell us where the NullPointerException occures? Commented Mar 7, 2014 at 17:15
  • @shkschneider...last line. myImage.setImageBitmap(myBitmap); Commented Mar 7, 2014 at 17:16
  • Test for myImage being null or myBitmap being null, could be many things at this point. Post more infos (stacktrace +1) Commented Mar 7, 2014 at 17:21

2 Answers 2

2

Wild guess: myImage is null. Check that you're importing the correct R.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are in an Activity, check if imageView1 is in the layout you passed to setContentView method.

If you are using a fragment or have inflated programmatically a layout, then use view.findViewBy(R.id.imageView1) instead

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.