M.ArslanKhan
M.ArslanKhan

Reputation: 3898

Null Pointer Exception while putting Image In Bitmap

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

    }

Upvotes: 0

Views: 88

Answers (2)

S.Thiongane
S.Thiongane

Reputation: 6905

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

Upvotes: 0

m0skit0
m0skit0

Reputation: 25873

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

Upvotes: 2

Related Questions