Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:当从三星gallery中选择图像时,应用程序崩溃(但它与谷歌照片应用程序配合使用)_Java_Android - Fatal编程技术网

Java Android:当从三星gallery中选择图像时,应用程序崩溃(但它与谷歌照片应用程序配合使用)

Java Android:当从三星gallery中选择图像时,应用程序崩溃(但它与谷歌照片应用程序配合使用),java,android,Java,Android,你好 当我从谷歌照片应用程序中选择图像时,以下代码起作用。然而,当我从三星股票库中选择相同的图片时,我的应用程序崩溃了 我进行了一些故障排除,发现问题出在getContentResolver.query上: 请帮帮我。谢谢。发布您的logcat错误。尝试查看getData是否返回null @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onAct

你好

当我从谷歌照片应用程序中选择图像时,以下代码起作用。然而,当我从三星股票库中选择相同的图片时,我的应用程序崩溃了

我进行了一些故障排除,发现问题出在getContentResolver.query上:


请帮帮我。谢谢。

发布您的logcat错误。尝试查看getData是否返回null
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PICK_IMAGE && resultCode == RESULT_OK && null != data) {
        Uri selectedImage = data.getData();

        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        //Error happens when program try to run the following line of code
        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);


        cursor.moveToFirst();

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

        Toast.makeText(getApplicationContext(), picturePath, Toast.LENGTH_LONG).show();
    }
}