Blurry icon indicating copy to clipboard operation
Blurry copied to clipboard

NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.recycle()' on a null object reference

Open ugurcany opened this issue 8 years ago • 15 comments

I'm getting the following err:

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 the following:

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 err occurs rarely. However, could you please solve this and update the library accordingly?

ugurcany avatar Feb 09 '17 07:02 ugurcany

I can confirm I'm also receiving exactly the same issue with the same code sample.

edwoollard avatar Feb 10 '17 09:02 edwoollard

Same here.

HugoMatilla avatar Feb 13 '17 12:02 HugoMatilla

+1

dominikmicuta avatar Feb 14 '17 08:02 dominikmicuta

@ugurcany When did you call Blurry.with? Is it too early? I mean before the view is attached to window?

However I think Blurry shouldn't make app crash or give some meaningful exception under this case at least.

zxx714 avatar Feb 15 '17 20:02 zxx714

@zxx714 In my case, the creation of blur view is done inside onShowListener() of a dialog that I create. And the dialog creation is triggered by a user input.

ugurcany avatar Feb 16 '17 07:02 ugurcany

@ugurcany Did you use Blurry to blur the background of your dialog?

What's the blurredView you passed in your code?

zxx714 avatar Feb 16 '17 07:02 zxx714

@zxx714 Yes, we can say that. I'm passing the rootview of my Activity as the view to be blurred. Just want to mention again that I rarely encounter this issue.

ugurcany avatar Feb 16 '17 08:02 ugurcany

For anybody facing this problem, this is probably related to running the code too soon after the view is loaded try this attach a runnable imageView.post(new Runnable() { @Override public void run() { Blurry.with(Payment.this) .radius(25) .sampling(2) .animate(500) .onto(payments); } });

kisinga avatar Feb 23 '17 21:02 kisinga

I found the following code from the source code. public static Bitmap of(View view, BlurFactor factor) { view.setDrawingCacheEnabled(true); view.destroyDrawingCache(); view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); Bitmap cache = view.getDrawingCache(); Bitmap bitmap = of(view.getContext(), cache, factor); cache.recycle(); return bitmap; } I don't know why call destroyDrawingCache() then call view.getDrawingCache(), so that may the cache is null,and then call cache.recycle(). This problem is caused by the difference version? And this is my calling code. Blurry.with(MainActivity.this) .capture(findViewById(R.id.coord_layout)) .into((ImageView) findViewById(R.id.bluur_img));

AlohaQwQ avatar Feb 27 '17 07:02 AlohaQwQ

I have a problem while calling notifyDataSetChanged();.

Error:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.sabith.restorentbiller.ItemsViewAdapter.notifyDataSetChanged()' on a null object reference

ameersabith avatar Aug 29 '17 13:08 ameersabith

Hello, i tried to use it on a FrameLayout, Containing a GLSurfaceView Which is displaying the Camera Stream. First i got the '"NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.recycle()'"

And then when I try using the pos(...)t method, it just does have no effect =) I 'assume this lib can't work on viewGroup with non-fixed background/ChildView =)

(Also related to this 'issue' https://github.com/wasabeef/Blurry/issues/73)

MensObscura avatar Jan 10 '18 10:01 MensObscura

My solution,

handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            Blurry.with(mContext).radius(25).capture(mImgAudio).into(mImgBlurryfloat);

        }
    },1000);

snowf07 avatar Apr 19 '18 07:04 snowf07

Kotlin approach:

private fun Blurry.Composer.postOnto(view: ViewGroup) {
    view.post { onto(view) }
}

jasonrobinson-gpsw avatar Jul 10 '18 16:07 jasonrobinson-gpsw

I faced same problem and tried all of above solutions but none of them works :( Also since "view.getDrawingCache()"has become decrypt since android API30, it seems necessary to delete all of the cache process...

sosmallsotiny avatar Mar 15 '22 11:03 sosmallsotiny

I'm facing this problem event with kotlin approach:

private fun Blurry.Composer.postOnto(view: ViewGroup) {
    view.post { onto(view) }
}

Oshuremy avatar Jun 20 '23 13:06 Oshuremy