简体   繁体   English

java.lang.IllegalArgumentException:column'_data'不存在

[英]java.lang.IllegalArgumentException: column'_data' does not exist

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. 当图像来自Picasa文件夹时,我得到此异常。

// 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;
        }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalArgumentException:列'foo'不存在android - java.lang.IllegalArgumentException: column 'foo' does not exist android CursorAdapter java.lang.IllegalArgumentException:列'_id'不存在 - CursorAdapter java.lang.IllegalArgumentException: column '_id' does not exist java.lang.IllegalArgumentException:列'_id'不存在-UploadActivity - java.lang.IllegalArgumentException: column '_id' does not exist - UploadActivity 错误:原因:java.lang.IllegalArgumentException:列“_id”不存在 - Error: Caused by: java.lang.IllegalArgumentException: column '_id' does not exist java.lang.IllegalArgumentException:Ormlite游标不存在列'_id' - java.lang.IllegalArgumentException: column '_id' does not exist with Ormlite cursor java.lang.IllegalArgumentException:列“_id”不存在 - java.lang.IllegalArgumentException: column '_id' does not exist Android SQLite java.lang.IllegalArgumentException:列'_id'不存在 - Android SQLite java.lang.IllegalArgumentException: column '_id' does not exist java.lang.IllegalArgumentException:列“状态”不存在 - java.lang.IllegalArgumentException: column 'status' does not exist 引起:java.lang.IllegalArgumentException:列'_id'不存在 - Caused by: java.lang.IllegalArgumentException: column '_id' does not exist java.lang.IllegalArgumentException:列“_data”不存在。 可用列:[] - java.lang.IllegalArgumentException: column '_data' does not exist. Available columns: []
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM