마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

갤러리 사진 선택시에 오류가 뜹니다

0 추천

버튼 클릭시 갤러리에 접근하여 사진을 선택해 보여주는 기능을 구현하고 싶습니다.

하지만 사진 선택 시 오류가 뜹니다

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.net_danong, PID: 13354
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { act=android.intent.action.PICK dat=content://media/external/images/media typ=image/* (has extras) }} to activity {com.example.net_danong/com.example.net_danong.WritePostActivity}: java.lang.NullPointerException: Argument must not be null
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
        at android.app.ActivityThread.-wrap19(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.NullPointerException: Argument must not be null
        at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:29)
        at com.bumptech.glide.util.Preconditions.checkNotNull(Preconditions.java:23)
        at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:669)
        at com.example.net_danong.WritePostActivity.onActivityResult(WritePostActivity.java:100)
        at android.app.Activity.dispatchActivityResult(Activity.java:7276)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312) 
        at android.app.ActivityThread.-wrap19(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

 

@Override
public void onBindViewHolder(@NonNull final GalleryViewHolder holder, int position) {
    CardView cardView = holder.cardView;
    cardView.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){
            Intent resultIntent = new Intent(Intent.ACTION_PICK);
            resultIntent. setDataAndType(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
            activity.startActivityForResult(resultIntent, GET_GALLERY_IMAGE);
            resultIntent.putExtra("profilePath", mDataset.get(holder.getAdapterPosition()));
            activity.setResult(RESULT_OK, resultIntent);
            activity.finish();
        }
                                });

    ImageView imageView = holder.cardView.findViewById(R.id.imageView);
    Glide.with(activity).load(mDataset.get(position)).centerCrop().override(500).into(imageView);
}//데이터(mDataset)가 하나씩 들어오는 곳



protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == GET_GALLERY_IMAGE && resultCode == RESULT_OK && data != null && data.getData() != null) {

        Uri selectedImageUri = data.getData();
        imageview.setImageURI(selectedImageUri);

    }

}
COUTH (140 포인트) 님이 2019년 12월 8일 질문

1개의 답변

0 추천
Caused by: java.lang.NullPointerException: Argument must not be null

갤러리 띄울 때 파라미터를 덜 넘긴 것 같네요.

 

쎄미 (162,410 포인트) 님이 2019년 12월 9일 답변
@Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            switch (requestCode) {
            case 0: {
                    if (resultCode == Activity.RESULT_OK) {
                            profilePath = data.getStringExtra("profilePath");
                            Bitmap bmp = BitmapFactory.decodeFile(profilePath);
                            profileImageView.setImageBitmap(bmp);

                    }
                break;
            }
        }
    }//profileImageView에 이미지 넣기

이렇게 했는데 계속 profileImageView.setImageBitmap(bmp); 이부분에 오류가 있다고 하네요ㅠ 뭐가 잘못된 걸까요?
profilePath가 제대로 오는지부터 확인해보면 되지 않을까요?
...