<p dir="auto">Glide Version: 4.2.0<br>
Integration libraries: OkHttp3<br>
Device/Android Version: SM-G5510;Android 6.0.1,level 23</p>
<p dir="auto">Wrap Code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public void onlyLoadAsGifBitmap(Context context, final View imageView, final String url, int width, int height, final int placeHoldId){
        if(isActivityDestroy(context)){
            return;
        }
        GlideApp.with(context).asGif().load(url).override(width, height).into(new SimpleTarget&lt;GifDrawable&gt;() {
            @Override
            public void onResourceReady(GifDrawable resource, Transition&lt;? super GifDrawable&gt; transition) {
                if(resource==null){
                    imageView.setBackgroundResource(placeHoldId);
                    return;
                }
                if(imageView instanceof  ImageView){
                    ((ImageView) imageView).setImageDrawable(resource);
                }else {
                    imageView.setBackground(resource);
                }
            }
            @Override
            public void onLoadFailed( Drawable errorDrawable) {
                imageView.setBackgroundResource(placeHoldId);
            }
        });
    }"><pre class="notranslate"><code class="notranslate">public void onlyLoadAsGifBitmap(Context context, final View imageView, final String url, int width, int height, final int placeHoldId){
        if(isActivityDestroy(context)){
            return;
        }
        GlideApp.with(context).asGif().load(url).override(width, height).into(new SimpleTarget&lt;GifDrawable&gt;() {
            @Override
            public void onResourceReady(GifDrawable resource, Transition&lt;? super GifDrawable&gt; transition) {
                if(resource==null){
                    imageView.setBackgroundResource(placeHoldId);
                    return;
                }
                if(imageView instanceof  ImageView){
                    ((ImageView) imageView).setImageDrawable(resource);
                }else {
                    imageView.setBackground(resource);
                }
            }
            @Override
            public void onLoadFailed( Drawable errorDrawable) {
                imageView.setBackgroundResource(placeHoldId);
            }
        });
    }
</code></pre></div>
<p dir="auto">Called Code:</p>
<p dir="auto"><code class="notranslate">onlyLoadAsGifBitmap(LauncherUI.this, tiaImageView, imageUrl, UITools.getWidth(), UITools.getHeight(), R.drawable.flash);</code></p>
<p dir="auto">Crash Report:</p>
<p dir="auto"><code class="notranslate">java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference  com.bumptech.glide.load.resource.gif.GifFrameLoader.int getWidth()(SourceFile:126)  com.bumptech.glide.load.resource.gif.GifDrawable.int getIntrinsicWidth()(SourceFile:215)  android.widget.ImageView.invalidateDrawable(ImageView.java:243)  android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:844)  android.graphics.drawable.Drawable.setVisible(Drawable.java:1575)  com.bumptech.glide.load.resource.gif.GifDrawable.boolean setVisible(boolean,boolean)(SourceFile:210)  android.widget.ImageView.onDetachedFromWindow(ImageView.java:1511)  android.view.View.dispatchDetachedFromWindow(View.java:15916)  android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3377)  android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3377)  android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3377)  android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3377)  android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3377)  android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3377)  android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3377)  android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3377)  android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3838)  android.view.ViewRootImpl.doDie(ViewRootImpl.java:7087)  android.view.ViewRootImpl.die(ViewRootImpl.java:7060)  android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:424)  android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:379)  android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:140)  android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5190)  android.app.ActivityThread.access$1700(ActivityThread.java:229)  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1880)  android.os.Handler.dispatchMessage(Handler.java:102)  android.os.Looper.loop(Looper.java:148)  android.app.ActivityThread.main(ActivityThread.java:7410)  java.lang.reflect.Method.invoke(Native Method)  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) </code></p>
<p dir="auto">now the crash occurs less,only affecting  two users.when readed <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="252315585" data-permission-text="Title is private" data-url="https://github.com/bumptech/glide/issues/2282" data-hovercard-type="issue" data-hovercard-url="/bumptech/glide/issues/2282/hovercard" href="https://github.com/bumptech/glide/issues/2282">#2282</a> and <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="249290516" data-permission-text="Title is private" data-url="https://github.com/bumptech/glide/issues/2231" data-hovercard-type="issue" data-hovercard-url="/bumptech/glide/issues/2231/hovercard" href="https://github.com/bumptech/glide/issues/2231">#2231</a> ,i find not same like  those,i only load gifDrawable for the view,instead of using cross-fade animation. i read this <a href="https://stackoverflow.com/questions/40450023/caused-by-java-lang-nullpointerexception-attempt-to-invoke-virtual-method-int" rel="nofollow">answer</a> and souce code related to gifDrawable ,but i still do'nt kown detail reason..</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
      at com.bumptech.glide.load.resource.gif.GifFrameLoader.getWidth(GifFrameLoader.java:127)
      at com.bumptech.glide.load.resource.gif.GifDrawable.getIntrinsicWidth(GifDrawable.java:215)
      at android.widget.ImageView.invalidateDrawable(ImageView.java:232)
      at android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:385)
      at android.graphics.drawable.Drawable.setVisible(Drawable.java:764)
      at com.bumptech.glide.load.resource.gif.GifDrawable.setVisible(GifDrawable.java:210)
      at android.widget.ImageView.onDetachedFromWindow(ImageView.java:1485)
      at android.view.View.dispatchDetachedFromWindow(View.java:14555)
      at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3063)
      at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3063)
      at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3063)
      at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4603)
      at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4576)
      at android.view.ViewGroup.removeView(ViewGroup.java:4507)
      at android.support.v4.view.ViewPager.removeView(ViewPager.java:1499)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1520)
      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
      at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3217)
      at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:3208)
      at android.support.v4.app.FragmentController.dispatchDestroy(FragmentController.java:262)
      at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:350)
      at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)
      at org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity.onDestroy(PassphraseRequiredActionBarActivity.java:83)
      at android.app.Activity.performDestroy(Activity.java:6407)
      at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1142)
      at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3818)"><pre class="notranslate"><code class="notranslate">  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
      at com.bumptech.glide.load.resource.gif.GifFrameLoader.getWidth(GifFrameLoader.java:127)
      at com.bumptech.glide.load.resource.gif.GifDrawable.getIntrinsicWidth(GifDrawable.java:215)
      at android.widget.ImageView.invalidateDrawable(ImageView.java:232)
      at android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:385)
      at android.graphics.drawable.Drawable.setVisible(Drawable.java:764)
      at com.bumptech.glide.load.resource.gif.GifDrawable.setVisible(GifDrawable.java:210)
      at android.widget.ImageView.onDetachedFromWindow(ImageView.java:1485)
      at android.view.View.dispatchDetachedFromWindow(View.java:14555)
      at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3063)
      at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3063)
      at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3063)
      at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4603)
      at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4576)
      at android.view.ViewGroup.removeView(ViewGroup.java:4507)
      at android.support.v4.view.ViewPager.removeView(ViewPager.java:1499)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1520)
      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
      at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3217)
      at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:3208)
      at android.support.v4.app.FragmentController.dispatchDestroy(FragmentController.java:262)
      at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:350)
      at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)
      at org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity.onDestroy(PassphraseRequiredActionBarActivity.java:83)
      at android.app.Activity.performDestroy(Activity.java:6407)
      at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1142)
      at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3818)
</code></pre></div>
<p dir="auto">I'm using Glide 4.3.0 to load GIFs into a RecyclerView. Some users are reporting that if they scroll quickly and then close the activity, they get a crash.</p>
<p dir="auto"><strong>Glide Version</strong>: 4.3.0</p>