Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide placeholder vector drawable resource not found exception

Recently I am trying to add Vector Drawable in my work. I am using glide to set my drawables. Here is my code :

Glide
                .with(mContext)
                .load(resDrawable)
                .placeholder(placeHolderResDrawable)
                .centerCrop()
                .bitmapTransform(new CropCircleTransformation(MyLruBitmapPool.getInstance()))
                .into(imgRoundedView);

Here I put vector drawable to resDrawable and placeHolderResDrawable. It was working fine in Lolipop device. But when I tested it in less than lolipop than it crashed. When trying to put drawable in placeholder it gave Resources$NotFoundException.

Here is the crash report:

android.content.res.Resources$NotFoundException: File res/drawable/default_round_profile.xml from drawable resource ID #0x7f02013d at android.content.res.Resources.loadDrawable(Resources.java:3451) at android.content.res.Resources.getDrawable(Resources.java:1894) at com.bumptech.glide.request.GenericRequest.getPlaceholderDrawable(GenericRequest.java:395) at com.bumptech.glide.request.GenericRequest.begin(GenericRequest.java:265) at com.bumptech.glide.manager.RequestTracker.runRequest(RequestTracker.java:36) at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:616) at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:652) at com.bumptech.glide.DrawableRequestBuilder.into(DrawableRequestBuilder.java:436)

like image 967
Sayem Avatar asked May 18 '16 11:05

Sayem


1 Answers

Try to get the drawable using ContextCompat and set it as placeholder:

ContextCompat.getDrawable(mContext, placeHolderResDrawable);

So it would be:

Glide.with(mContext)
     .load(resDrawable)
     .placeholder(ContextCompat.getDrawable(mContext, placeHolderResDrawable))
     .centerCrop()
     .bitmapTransform(new CropCircleTransformation(MyLruBitmapPool.getInstance()))
     .into(imgRoundedView);

Update for Glide v4:

Glide.with(mContext)
     .load(resDrawable)
     .apply(new RequestOptions()
         .placeholder(ContextCompat.getDrawable(mContext, placeHolderResDrawable))
         .centerCrop()
         .transform(new CropCircleTransformation(MyLruBitmapPool.getInstance())))
     .into(imgRoundedView);
like image 72
Sdghasemi Avatar answered Sep 24 '22 03:09

Sdghasemi