Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glide 4.2.0 Failed to find any ModelLoaders for model BitmapDrawable #2461

Closed
vsay01 opened this issue Oct 9, 2017 · 2 comments
Closed

Glide 4.2.0 Failed to find any ModelLoaders for model BitmapDrawable #2461

vsay01 opened this issue Oct 9, 2017 · 2 comments

Comments

@vsay01
Copy link

vsay01 commented Oct 9, 2017

Glide Version: com.github.bumptech.glide:glide:4.2.0

Integration libraries: No

Device/Android Version: Samsung

What happened
I want to load gif images that stored locally. I get the drawable based on the name of the file. when try to load with glide it's crash with the logcat below.

  • If i access to the file with R.drawable.anygif then it's working fine.

  • With GlideApp.load(getDrawable(mContext, "filename")), In the logcat it says Failed to find any ModelLoaders for model BitmapDrawable, but BitmapDrawable is a subclass of Drawable then it would be better if this can be load as well.

  • With GlideApp.load(getDrawable(mContext, "filename")), If i use it in placeholder then gif not working ( just an image ).

Any idea?

Glide load line / GlideModule (if any) / list Adapter code (if any):
Working

GlideApp.with(mContext)
                        .load(R.drawable.anygif)
                        .override(320)
                        .diskCacheStrategy(DiskCacheStrategy.DATA)
                        .placeholder(R.mipmap.placeholder)
                        .into(fakePageVH.mImgSticker);

Not Working

GlideApp.with(mContext)
                        .load(getDrawable(mContext, "filename"))
                        .override(320)
                        .diskCacheStrategy(DiskCacheStrategy.DATA)
                        .placeholder(R.mipmap.ic_launcher_round)
                        .into(fakePageVH.mImgSticker);

Working but gif not play, just an image

GlideApp.with(mContext)
                        .load("")
                        .override(320)
                        .diskCacheStrategy(DiskCacheStrategy.DATA)
                        .placeholder(getDrawable(mContext, "filename"))
                        .into(fakePageVH.mImgSticker);

Helper

public static Drawable getDrawable(Context context, String ImageName) {
        return ContextCompat.getDrawable(context, context.getResources().getIdentifier(ImageName, "drawable", context.getPackageName()));
    }

Stack trace / LogCat:

com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders for model: android.graphics.drawable.BitmapDrawable@ad5185c
                                                                             at com.bumptech.glide.Registry.getModelLoaders(Registry.java:543)
                                                                             at com.bumptech.glide.load.engine.DecodeHelper.getLoadData(DecodeHelper.java:186)
                                                                             at com.bumptech.glide.load.engine.DecodeHelper.getCacheKeys(DecodeHelper.java:204)
                                                                             at com.bumptech.glide.load.engine.DataCacheGenerator.<init>(DataCacheGenerator.java:33)
                                                                             at com.bumptech.glide.load.engine.DecodeJob.getNextGenerator(DecodeJob.java:278)
                                                                             at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:259)
                                                                             at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:230)
                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                             at java.lang.Thread.run(Thread.java:762)
                                                                             at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:386)
@vsay01
Copy link
Author

vsay01 commented Oct 9, 2017

I am be able to load local gif files.

Instead pass the drawable to load method, I changed the helper method to return only the int, the associated resource identifier.

I changed the getDrawable method as follow:

public static int getDrawable(Context context, String ImageName) {
        return context.getResources().getIdentifier(ImageName, "drawable", context.getPackageName());
    }

Note: the imageName cannot have the extension otherwise it won't load.

Working with filename

GlideApp.with(mContext)
                        .load(getDrawable(mContext, "filename"))
                        .override(320)
                        .diskCacheStrategy(DiskCacheStrategy.DATA)
                        .placeholder(R.mipmap.ic_launcher_round)
                        .into(fakePageVH.mImgSticker);

Not Working with filename.gif

GlideApp.with(mContext)
                        .load(getDrawable(mContext, "filename.gif"))
                        .override(320)
                        .diskCacheStrategy(DiskCacheStrategy.DATA)
                        .placeholder(R.mipmap.ic_launcher_round)
                        .into(fakePageVH.mImgSticker);

Suggestion
The original issue is still there; it would be great if Glide can add the model so BitmapDrawable can be loaded.
I will keep this thread open so that we can track the original issue; otherwise, if found that Glide won't need to support BitmapDrawable then feel free to close this.

Thanks for great library.

@sjudd
Copy link
Collaborator

sjudd commented Oct 10, 2017

Thanks!

Duplicate of #122

@sjudd sjudd closed this as completed Oct 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants