Image를 클릭하여 ImageView에 표시하고 있습니다. 아래 코드는 내 코드입니다. 권한이 부여되면 코드 아래에서 실행됩니다.이미지를 클릭하여 ImageView에 표시
private void clickImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageFile = new File(itemName.getText().toString()+".jpg");
Uri tempuri = Uri.fromFile(imageFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT,tempuri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,1);
startActivityForResult(intent,0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 0)
{
switch (resultCode){
case Activity.RESULT_OK:
Log.d("path",imageFile.getAbsolutePath());
Toast.makeText(this,"file saved"+imageFile.getAbsolutePath(),Toast.LENGTH_LONG).show();
ImageView imv = (ImageView) findViewById(R.id.itemImage);
Bitmap photo = (Bitmap) data.getExtras().get("data");
imv.setImageBitmap(photo);
break;
case Activity.RESULT_CANCELED:
break;
default:break;
}
}
}
오류 로그.
03-01 17:51:47.183 5883-5883/com.lab.yourhomebasket E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lab.yourhomebasket, PID: 5883
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=null} to activity {com.lab.yourhomebasket/com.lab.yourhomebasket.AddItemActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:3720)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3763)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1403)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at com.lab.yourhomebasket.AddItemActivity.onActivityResult(AddItemActivity.java:107)
at android.app.Activity.dispatchActivityResult(Activity.java:6470)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3716)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3763)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1403)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
테스트를 위해 moto g3을 사용하고 있습니다. 이미지가 내 ImageView에 표시되지 않습니다. 도와주세요. the documentation for ACTION_IMAGE_CAPTURE
을 인용