wasabeef / Blurry

Blurry is an easy blur library for Android
Apache License 2.0
5.57k stars 602 forks source link

Fragments #79

Open AhmadHossam10 opened 6 years ago

AhmadHossam10 commented 6 years ago

Blurry doesn't work with fragments always giving me null pointer exception

@easycheese @wasabeef @Pkmmte @JasonCromer can you help please ?

iyashamihsan commented 4 years ago

Blurry gives null pointer exception in Fragment NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.recycle()' on a null object reference

Blurry.with(getContext()).radius(25).sampling(2).onto(mainLayout);

JasonCromer commented 4 years ago

@iyashamihsan when is this happening while you are blurring the image? Is the fragment being recreated at any point before this crash occurs?

JasonCromer commented 4 years ago

Maybe you can share a bit more code and a larger stack trace, please.

patilvishwanath commented 3 years ago

@JasonCromer Please find below issue with fragments : Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.recycle()' on a null object reference at jp.wasabeef.blurry.internal.Blur.of(SourceFile:42) at jp.wasabeef.blurry.Blurry$Composer.onto(SourceFile:115) ...................

while calling below,

Blurry.with(activity) .radius(40) .sampling(2) .color(ResourcesUtil.getColor(R.color.dirtyBlack25)) .onto(blurredView);

As far as I understood, the err occurs here inside of method of Blur class:

Bitmap cache = view.getDrawingCache(); cache.recycle();

Here, the drawing cache can be null sometimes. This happens when Fragments are used with BottomNavigation Bar. Fragment is removed and redrawn.

The possible solution/ workaround could be to add a null check for bitmap and then recycle.

AMV007 commented 2 years ago

Have similar issue, do you have good solution for this problem ?