When click pic directly from app it's crash from this lines. this problem is getting only on Android 11, working fine on other devices
Errors:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isMutable()' on a null object reference at com.my.collegemaker.collagelib.Utility.decodeFile(Utility.java:115) at com.my.collegemaker.collagelib.CollageActivity$BitmapWorkerTask.doInBackground(CollageActivity.java:262) at com.my.collegemaker.collagelib.CollageActivity$BitmapWorkerTask.doInBackground(CollageActivity.java:227)
@SuppressLint({"NewApi"})
public static Bitmap decodeFile(String path, int requiredSize, boolean isScrapBook) {
try {
File f = new File(path);
Options boundsOption = new Options();
boundsOption.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f), null, boundsOption);
Options o2 = new Options();
if (isScrapBook) {
o2.inMutable = true;
}
o2.inSampleSize = calculateInSampleSize(boundsOption, requiredSize, requiredSize);
Bitmap bitmap = BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
ExifInterface exif = null;
try {
exif = new ExifInterface(path);
} catch (IOException e) {
e.printStackTrace();
}
bitmap = rotateImage(bitmap, exif.getAttributeInt("Orientation", 0));
if (bitmap.isMutable()) {
return bitmap;
}
Bitmap mutableBitmap = bitmap.copy(Config.ARGB_8888, true);
if (mutableBitmap != bitmap) {
bitmap.recycle();
}
return mutableBitmap;
} catch (FileNotFoundException e2) {
return null;
}
}
App Crash On This Line
bitmap = rotateImage(bitmap, exif.getAttributeInt("Orientation", 0));
if (bitmap.isMutable()) {
return bitmap;