Shubham Nandanwar Shubham Nandanwar - 1 month ago 4x
Android Question

Issue in fetching image from SD card and displaying on an ImageView

I found a program on this page to fetch image from sd card and show it on an imageView. I am getting issue at this line -

bitmap = BitmapFactory.decodeFile(picturePath);

I am getting correct value of picturePath variable but in the above line it is setting bitmap value as null. I had visited various threads and almost everyone is using this same line. I am not getting what is wrong with my code

Here is my complete code -

private Button upload;
ImageView imgView;
EditText caption;
Bitmap bitmap;

protected void onCreate(Bundle savedInstanceState) {

imgView = (ImageView) findViewById(;

upload = (Button) findViewById(;
caption = (EditText) findViewById(;
upload.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

Intent i = new Intent(Intent.ACTION_PICK,
startActivityForResult(i, 2);

public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == 2 && resultCode == RESULT_OK
&& null != data) {

Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };

Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);

bitmap = BitmapFactory.decodeFile(picturePath);


Try putting this in your AndroidManifest.xml

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

After that, make sure you have the permission enabled in the App Info screen on your device.