Can';t将图像设置为Android中图像库中的imageview

Can';t将图像设置为Android中图像库中的imageview,android,android-intent,imageview,android-gallery,Android,Android Intent,Imageview,Android Gallery,Logcat错误 java.lang.RuntimeException:未能传递结果ResultInfo{who=null,请求=0,结果=-1,数据=Intent{dat=content://media/external/images/media/232 flg=0x1}}到活动{com.leadconcept.whopopsup/com.leadconcept.whopopsup.CameraActivity}:java.lang.NullPointerException 位于com.le

Logcat错误

  • java.lang.RuntimeException:未能传递结果ResultInfo{who=null,请求=0,结果=-1,数据=Intent{dat=content://media/external/images/media/232 flg=0x1}}到活动{com.leadconcept.whopopsup/com.leadconcept.whopopsup.CameraActivity}:java.lang.NullPointerException
  • 位于com.leadconcept.whopopsup.CameraActivity.onActivityResult(CameraActivity.java:131)
第二个logcat错误将我带到以下代码行:

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_CANCELED) {
      if (requestCode == PICK_IMAGE) {
        Uri selectedImageUri = data.getData();
        Log.d("PICK_IMAGE", selectedImageUri.toString());
        Dialog settingsDialog = new Dialog(this);
        settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.custom_dailogue, null));
        img_in_dailogue = (ImageView) findViewById(R.id.img_in_dailogue);
        ImageView img_in_dailogue = new ImageView(this);
        LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        img_in_dailogue.setLayoutParams(vp);
        img_in_dailogue.setMaxHeight(250);
        img_in_dailogue.setMaxWidth(350);
        img_in_dailogue.setImageURI(Uri.parse(selectedImageUri.toString()));
        settingsDialog.show();
      }
    }
  }
那代码有什么问题?我不明白为什么不能将imageUri发送到imageview。我还验证了传递给setImageURI函数的Uri值是否正确

img_in_dailogue.setImageURI(Uri.parse(selectedImageUri.toString()));
在初始化它之前,你不是在dailogue中使用了img吗?难道不是:

img_in_dailogue = (ImageView) findViewById(R.id.img_in_dailogue);
ImageView img_in_dailogue = new ImageView(this);

是的,这是一个拼写错误。我将尝试这个ImageView img_in_dailogue=新的ImageView(这个);如果imageview已经存在于xml中,那么为什么我们需要创建新的imageview(这一点)。我们不能设置唯一的Uri变量吗。img_in_dailogue.setImageURI(Uri.parse(selectedImageUri.toString()))
ImageView img_in_dailogue = new ImageView(this);
img_in_dailogue = (ImageView) findViewById(R.id.img_in_dailogue);