@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();
}
}
}
Logcat错误
- java.lang.RuntimeException:传递结果失败ResultInfo {who = null,request = 0,result = -1,data = Intent {dat = content:// media / external / images / media / 232 flg = 0x1} } to activity {com.leadconcept.whopopsup / com.leadconcept.whopopsup.CameraActivity}:java.lang.NullPointerException
- at com.leadconcept.whopopsup.CameraActivity.onActivityResult(CameraActivity.java:131)
第二个logcat错误将我带到这行代码:
img_in_dailogue.setImageURI(Uri.parse(selectedImageUri.toString()));
该代码有什么问题?我无法理解为什么我不能将imageUri发送到imageview。我还验证了我传递给setImageURI函数的Uri值是正确的。
答案 0 :(得分:0)
img_in_dailogue = (ImageView) findViewById(R.id.img_in_dailogue);
ImageView img_in_dailogue = new ImageView(this);
在初始化之前,你不是在使用img_in_dailogue
(它是“对话”btw,而不是dailogue)吗?不应该是:
ImageView img_in_dailogue = new ImageView(this);
img_in_dailogue = (ImageView) findViewById(R.id.img_in_dailogue);
HTH。