[英]Can't set the image to imageview from image gallery in Android
@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}}傳遞給活動失敗{com.leadconcept.whopopsup / com.leadconcept.whopopsup.CameraActivity}:java.lang.NullPointerException
- 在com.leadconcept.whopopsup.CameraActivity.onActivityResult(CameraActivity.java:131)
第二個logcat錯誤將我帶到以下代碼行:
img_in_dailogue.setImageURI(Uri.parse(selectedImageUri.toString()));
該代碼有什么問題? 我不明白為什么無法將imageUri發送到imageview。 我還驗證了我傳遞給setImageURI函數的Uri值正確。
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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.