Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalArgumentException: column'_data' does not exist

Tags:

android

public static String getFilePathFromUri(Uri uri, Context c) {
    try {
        String filePath = null;
        String scheme = uri.getScheme();
        if (scheme != null && scheme.equals("content")) {
            ContentResolver contentResolver = c.getContentResolver();
            Cursor cursor = contentResolver.query(uri, null, null, null,
                    null);
            cursor.moveToFirst();
            filePath = cursor.getString(cursor
                    .getColumnIndexOrThrow(Images.Media.DATA));
        }
        return filePath;
    } catch (Exception e) {
        //java.lang.illegalArgumentException: column'_data' does not exist
        return null;
    }
}

I get this Exception When the Image is from Picasa folder.

like image 828
Archie.bpgc Avatar asked Sep 18 '13 07:09

Archie.bpgc


1 Answers

// try this way,hope this will help you...

public String getAbsolutePath(Uri uri) {
        if(Build.VERSION.SDK_INT >= 19){
            String id = uri.getLastPathSegment().split(":")[1];
            final String[] imageColumns = {MediaStore.Images.Media.DATA };
            final String imageOrderBy = null;
            Uri tempUri = getUri();
            Cursor imageCursor = getContentResolver().query(tempUri, imageColumns,
                    MediaStore.Images.Media._ID + "="+id, null, imageOrderBy);
            if (imageCursor.moveToFirst()) {
                return imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
            }else{
                return null;
            }
        }else{
            String[] projection = { MediaColumns.DATA };

            Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
            if (cursor != null) {
                int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
                cursor.moveToFirst();
                return cursor.getString(column_index);
            } else
                return null;
        }

}
like image 79
Haresh Chhelana Avatar answered Oct 02 '22 23:10

Haresh Chhelana