问题
I am trying to load an image into imageView
through Glide. But the image is not loaded - I get an error.
I'm using the following code
GlideApp.with(context)
.load(itemData.getThumbnailUri())
.placeholder(R.mipmap.koya_logo_white)
.error(R.mipmap.ic_image_loading_error)
.into(itemBinding.cover);
Logs
lide: Load failed for https://s3.amazonaws.com/koya-dev-videos/kindness/8da807aa-1e1e-413d-bf9b-5bb084646593/medialibrary/9456621508/videos/1eb78337-d569-41bd-95ad-153d9098de03.png with size [1080x1080]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{StringUri->Object->Drawable}, LOCAL, DataCacheKey{sourceKey=https://s3.amazonaws.com/koya-dev-videos/kindness/8da807aa-1e1e-413d-bf9b-5bb084646593/medialibrary/9456621508/videos/1eb78337-d569-41bd-95ad-153d9098de03.png, signature=EmptySignature}
Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{StringUri->Drawable->Drawable}
Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{StringUri->Bitmap->Drawable}
回答1:
Am also faced this issue.Its bug from glide side.Use the latest version of glide.
repositories {
mavenCentral()
google()
}
dependencies {
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}
Make sure that itemData.getThumbnailUri() not contain empty space
回答2:
Another reason why this problem appears is the phone/emulator doesn't have an internet connection.
回答3:
Try this
String url = "https://s3.amazonaws.com/koya-dev-videos/kindness/8da807aa-1e1e-413d-bf9b-5bb084646593/medialibrary/9456621508/videos/1eb78337-d569-41bd-95ad-153d9098de03.png";
GlideApp.with(context).load(url)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.error(R.drawable.glide_app_img_loader)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(imageView);
回答4:
I found that Glide
is not able to load HTTP
urls but works fine if we use HTTPS
over HTTP
.
As well it fails to loads large images like if image is 1800x1800 or more, it fails to load that much data of image. So the best option is to use RequestOptions#override()
and apply it to Glide
, in such case.
try {
String url = "" /* URL of Image */;
if (url.startsWith("http://"))
url = url.replace("http://", "https://");
RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.mipmap.app_icon);
requestOptions.error(R.mipmap.app_icon);
Glide
.with(context)
.setDefaultRequestOptions(requestOptions)
.load(url)
.into(imgView);
} catch (Exception e) {
e.printStackTrace();
}
回答5:
The solution works for me:
1. Update build.gradle(Module: app)
implementation "com.github.bumptech.glide:glide:4.7.1"
kapt "com.github.bumptech.glide:compiler:4.7.1"
implementation "com.squareup.okhttp3:okhttp:3.14.0"
implementation ('com.github.bumptech.glide:okhttp3-integration:4.7.1'){
exclude group: 'glide-parent'
}
Set timeout for glide
@GlideModule class MyAppGlideModule : AppGlideModule() { override fun registerComponents(context: Context, glide: Glide, registry: Registry) { val client = OkHttpClient.Builder() .readTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS) .build() val factory = OkHttpUrlLoader.Factory(client) glide.registry.replace(GlideUrl::class.java, InputStream::class.java, factory) } }
回答6:
Same with @ievgen answers.
- Check for your internet connection
- HTTPS connection issue for Android 8 or 9, see here
- The issue might occur due to invalid URL or having a trailing space or
/
slash
My project was getting an API from TMDB, and using val BASE_IMAGE = http://image.tmdb.org/t/p/w780/
notice the last trailing w780/
"slash"?
It is concatenated mistakenly e.g:
W/Glide: Load failed for http://image.tmdb.org/t/p/w780//qJdfO3ahgAMf2rcmhoqngjBBZW1.jpg with size [-2147483648x-2147483648]
Removing the trailing /
slash fixed my issue. E.g from:
http://image.tmdb.org/t/p/w780/ -> http://image.tmdb.org/t/p/w780
Here's my setup:
Glide: 4.9.0
Android Studio: 3.4.1 (Grale Build Tools)
来源:https://stackoverflow.com/questions/55473076/class-com-bumptech-glide-load-engine-glideexception-failed-to-load-resource