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

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?

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 43
  • Comments: 15

Most upvoted comments

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); } });

Kotlin approach:

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

My solution,

handler.postDelayed(new Runnable() {

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

        }
    },1000);