asantibanez / Patio

A minimalistic Android view widget for selecting multiple images
MIT License
106 stars 18 forks source link

problem on getRealPathFromURI #8

Open lipe-dev opened 9 years ago

lipe-dev commented 9 years ago

Hi, this method was throwing out a NullPointerException when trying to attach a picture from my device and crashing my app, I found this on StackOverflow:

public String getRealPathFromURI(Context context, Uri contentUri) {
  Cursor cursor = null;
  try { 
    String[] proj = { MediaStore.Images.Media.DATA };
    cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}

and this code seems to solve the problem.

wviana commented 9 years ago

@asantibanez This is probably the reason why It was crashing in the emulator as I told you some time ago. When I get some time I'll test it in my fork and than pull-request it to you.