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

비트맵 정방향 가져오기에서 int orientation에서 null에러

0 추천
 //사진보내기
    public void sendimage(View view) {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(intent, REQUST_IMAGE_GET);
    }

    private String getRealPathFromURI(Uri contentUri) {
        int column_index=0;
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor cursor = getContentResolver().query(contentUri, proj, null, null, null);
        if(cursor.moveToFirst()){
            column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        }

        return cursor.getString(column_index);
    }


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

        if (requestCode == REQUST_IMAGE_GET && resultCode == RESULT_OK && data != null) {
            Uri fullPhotoUri = data.getData();
            assert fullPhotoUri != null;
            String fullstring = fullPhotoUri.toString();
            String realpath=getRealPathFromURI(fullPhotoUri);


            ExifInterface exif = null;
            try {
                exif = new ExifInterface(realpath);
            } catch (IOException e) {
                e.printStackTrace();
            }
            assert exif != null;
            int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

.....................

마지막줄 exiforientation에서 밑에 에러발생합니다 

error: Attempt to invoke virtual method 'int android.media.ExifInterface.getAttributeInt(java.lang.String, int)' on a null object reference

 

minsdk19

targetsdk28

 

어떻게하면 좋을까요 고수님들 ㅠㅠ

+exif 로그로 확인했더니 nullorientation나왔는데 null이 나왔단거겠죠?

안드린이 (2,520 포인트) 님이 2018년 12월 21일 질문
안드린이님이 2018년 12월 21일 수정

1개의 답변

0 추천
 
채택된 답변
realpath 변수의 경로가 잘못 되었거나, 해당 경로의 접근 권한 문제가 아닌가 싶네요.
디자이너정 (42,810 포인트) 님이 2018년 12월 22일 답변
안드린이님이 2018년 12월 22일 채택됨
권한문제였네요 감사합니다 ! ㅎㅎ
...