com.bumptech.glide.load.engine.GlideException类:无法加载资源

时间:2019-04-02 10:57:52

标签: android image android-glide

我正在尝试通过Glide将图像加载到imageView中。但是图像未加载-我收到错误消息。 我正在使用以下代码

GlideApp.with(context)
    .load(itemData.getThumbnailUri())
    .placeholder(R.mipmap.koya_logo_white)
    .error(R.mipmap.ic_image_loading_error)
    .into(itemBinding.cover);

日志

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}

13 个答案:

答案 0 :(得分:3)

最简单的解决方案

添加,

android:usesCleartextTraffic="true"

<application/> 文件的 AndroidManifest.xml 标签内。

答案 1 :(得分:2)

出现此问题的另一个原因是电话/仿真器没有互联网连接。

答案 2 :(得分:0)

我也遇到了这个问题。它的滑行错误来自于滑行。请使用最新版本的滑行。

repositories {
 mavenCentral()
 google()
}

dependencies {
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}

确保itemData.getThumbnailUri()不能包含空格

答案 3 :(得分:0)

尝试一下

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 :(得分:0)

我发现 Glide 无法加载HTTP网址,但是如果我们在HTTPS上使用HTTP,效果很好。

同样,它无法加载较大的图像(例如,如果图像为1800x1800或更高),则无法加载大量图像数据。因此,在这种情况下,最好的选择是使用RequestOptions#override()并将其应用于Glide

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 :(得分:0)

该解决方案对我有用:
    1.更新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'
        }
  1. 设置滑行超时时间

     @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 :(得分:0)

与@ievgen答案相同。

  • 检查您的互联网连接
  • Android 8 9 的HTTPS连接问题,请参见here
  • 该问题可能是由于无效的URL或带有空格或/的斜杠引起的。

我的项目正在从TMDB获取API,并使用val BASE_IMAGE = http://image.tmdb.org/t/p/w780/注意最后一个尾随w780/的“斜杠”?

它被错误地串联,例如:

W/Glide: Load failed for http://image.tmdb.org/t/p/w780//qJdfO3ahgAMf2rcmhoqngjBBZW1.jpg with size [-2147483648x-2147483648]

删除结尾的/斜杠解决了我的问题。例如:

http://image.tmdb.org/t/p/w780/ -> http://image.tmdb.org/t/p/w780

这是我的设置:

Glide: 4.9.0
Android Studio: 3.4.1 (Grale Build Tools)

答案 7 :(得分:0)

对我来说,问题出在Http...HTTP...上。我将其更改为http...(所有小写字母),并且可以正常工作。

GlidePicasso都有相同的问题。

答案 8 :(得分:0)

出现此错误的另一个可能原因是: not having enough free space on the internal memory

检查设备的可用内部存储空间。如果它太低,请释放一些空间。

答案 9 :(得分:0)

我也有这个问题。 当我这样写布局时

<FrameLayout 
    android:layout_width="@dimen/view_width"
    android:layout_height="@dimen/view_height">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</FrameLayout>

然后我将其更改为

<FrameLayout 
    android:layout_width="@dimen/view_width"
    android:layout_height="@dimen/view_height">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</FrameLayout>

此解决方案对我有用。

答案 10 :(得分:0)

像这样创建图像解码器:

class PageDecoder(
    private val bitmapPool: BitmapPool
) : ResourceDecoder<InputStream, Bitmap> {

    companion object {
        val PAGE_DECODER: Option<Boolean> = Option.memory("abc")
    }

    override fun decode(source: InputStream, width: Int, height: Int, options: Options): Resource<Bitmap>? {
        return BitmapResource.obtain(BitmapFactory.decodeStream(source), bitmapPool)
    }

    override fun handles(source: InputStream, options: Options): Boolean = options.get(PAGE_DECODER) ?: false

}

在你的滑翔模块中应该应用这个:

override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        registry.prepend(InputStream::class.java, Bitmap::class.java, PageDecoder(glide.bitmapPool))
    }

在那里你加载图像的活动使用这个:

GlideApp.with(context)
        .load("Image url or path, etc")
        .apply(GlideOptions.option(PageDecoder.PAGE_DECODER, true))
        .into(imageview)

这对我有用,希望对您有所帮助。

答案 11 :(得分:0)

检查您传递的 Uri 是否正确,对我来说这是传递的 Uri 中的错误,因为我两次追加所需的 BaseUri

答案 12 :(得分:-2)

我认为您没有为您的应用添加访问互联网的权限。

<块引用>

将此添加到您的 AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
相关问题