Glide版本4.9.0中的空位图

时间:2019-06-20 09:05:46

标签: android bitmap android-glide

当我尝试在可缩放ImageView中加载图像时,应用程序崩溃并出现以下错误:

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference

错误显示在代码.into(imageView)的最后一行。

 Glide.with(context).asBitmap()
            .load(url)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .listener(new RequestListener<Bitmap>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, 
Object model, Target<Bitmap> target, boolean isFirstResource) {
                    AppLog.i(TAG, "on Exception. Exception message: " + 
   JsonUtils.jsonify(e));
                    showSnackBarTop((Activity) context, 
   context.getString(R.string.error_internet));
                    hideLoader();
                    return false;
                }

                @Override
                public boolean onResourceReady(Bitmap resource, Object 
           model, Target<Bitmap> target, DataSource dataSource, boolean 
            isFirstResource) {
                    AppLog.i(TAG, "on ResourceReady.");
                    hideLoader();
                    return false;
                }
            }).transition(GenericTransitionOptions.with(R.anim.imagefadein_animation))
            .into(imageView);

0 个答案:

没有答案