Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.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 安卓:当我在gallery应用程序中选择一张图片时,应用程序不见了_Java_Android_Runtime Error_Android Gallery_Runtimeexception - Fatal编程技术网

Java 安卓:当我在gallery应用程序中选择一张图片时,应用程序不见了

Java 安卓:当我在gallery应用程序中选择一张图片时,应用程序不见了,java,android,runtime-error,android-gallery,runtimeexception,Java,Android,Runtime Error,Android Gallery,Runtimeexception,我的应用程序访问基本图库应用程序 当我选择图片时,应用程序将消失,并出现以下错误: E/AndroidRuntime(29852): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://media/external/images/media/9013 (has extras) }} to activi

我的应用程序访问基本图库应用程序

当我选择图片时,应用程序将消失,并出现以下错误:

E/AndroidRuntime(29852): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://media/external/images/media/9013 (has extras) }} to activity {com.example.rusk/com.example.rusk.MainActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/9013 from pid=29852, uid=10097 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
我的代码如下:

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    intent.setAction(Intent.ACTION_GET_CONTENT);

    startActivityForResult(Intent.createChooser(intent, "Intent.createChooser"), SELECT_PICTURE);

}
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    Toast.makeText(this, "onActivityResult 실행", Toast.LENGTH_LONG).show();
      if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE) {
                Uri selectedImageUri = data.getData();
                selectedImagePath = getPath(selectedImageUri);
                System.out.println("Image Path : " + selectedImagePath);
                img.setImageURI(selectedImageUri);
            }
        }
}
   public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }

您应该在清单文件中添加权限,如

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


正如你的错误所说

你读到错误了吗?