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();
}
});
onCameraClickedListenerisnullwhen you want to callcapture()on it.capture()on it.