0

I have an android app which is capturing the location. I have tried to check the permissions required on android 15 and also the context passed. Help me trace and fix the issue as it is occuring only on device 15.The below code is working fine for all devices of android 14 and below but on android 15 it causes a crash with the below message.

Exception is:

java.lang.NullPointerException: Attempt to invoke interface method 'void ant.co.in.geotagginglibraryLocationApp.GeoLocationPopup$OnCameraClickedListener.capture()' on a null object reference
    at anant.co.in.geotagginglibraryLocationApp.GeoLocationPopup$1.onClick(GeoLocationPopup.java:183)

I am attaching the code, please help to resolve.

 addlocation.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            addlocation.setEnabled(false);
            if (!showValidations(context)) {
                onCameraClickedListener.capture();
                addlocation.setEnabled(true);
            }
            addlocation.setEnabled(true);
        }
    });

 private void openCamera() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        File photoFile = null;
        try {
            photoFile = imageUtils.createImageFile(PREFIX_GEO_TAG_IMG);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        if (photoFile != null) {
            imagePath = photoFile.getAbsolutePath();
            Uri photoURI = FileProvider.getUriForFile(getActivity(), "anant.co.in.geotagginglibraryAculife.FileProvider", photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_CAPTURE_IMAGE);
        }
    }
}

 doctortag.setOnCameraClickedListener(new GeoLocationPopup.OnCameraClickedListener() {
                    @Override
                    public void capture() {
                        openCamera();
                    }
                });
3
  • The error tells you that onCameraClickedListener is null when you want to call capture() on it. Commented Jan 14 at 14:53
  • @Robert- how do I resolve it? Commented Jan 15 at 4:43
  • Whatever this variable is, you have to make sure you assign an instance to it before you execute capture() on it. Commented Jan 15 at 7:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.