You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Glide无法将图片加载至RecyclerView内的ImageView问题求助

Glide加载RecyclerView中ImageView图片失败的解决办法

我尝试用Glide把图片加载到RecyclerView的ImageView里,出现加载错误。初始时占位图能正常显示,但1秒后会切换为错误图标(星形Drawable)。

初始Glide代码

val imageStringAddress = review.userImage //URL
val options: RequestOptions = RequestOptions()
    .centerCrop()
    .placeholder(R.drawable.dota_logo) //占位图
    .error(R.drawable.ic_baseline_star_24) //错误图
Glide.with(this.context).load(imageStringAddress).apply(options).into(userIconImage); //将URL加载到ImageView

尝试过的无效代码

Glide.with(this.context).load(imageStringAddress).apply(options)
    .override(com.bumptech.glide.request.target.Target.SIZE_ORIGINAL, com.bumptech.glide.request.target.Target.SIZE_ORIGINAL).listener(
        object : RequestListener<Drawable> {
            override fun onLoadFailed(
                e: GlideException?,
                model: Any?,
                target: com.bumptech.glide.request.target.Target<Drawable>?,
                isFirstResource: Boolean
            ): Boolean {
                return false
            }

            override fun onResourceReady(
                resource: Drawable?,
                model: Any?,
                target: com.bumptech.glide.request.target.Target<Drawable>?,
                dataSource: DataSource?,
                isFirstResource: Boolean
            ): Boolean {
                return false
            }

        }
    ).into(userIconImage)

日志信息

2022-07-29 21:08:29.454 11232-11269/com.sirius.test_app D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-07-29 21:08:29.456 11232-11269/com.sirius.test_app I/chatty: uid=10154(com.sirius.test_app) glide-source-th identical 4 lines
2022-07-29 21:08:29.457 11232-11269/com.sirius.test_app D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-07-29 21:08:29.469 11232-11232/com.sirius.test_app W/Glide: Load failed for https://ibb.co/WcJMjSw with size [99x99]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There were 8 root causes:
    java.lang.RuntimeException(setDataSourceCallback failed: status = 0x80000000)
    java.lang.RuntimeException(setDataSourceCallback failed: status = 0x80000000)
    java.lang.RuntimeException(setDataSource failed: status = 0x80000000)
    java.lang.RuntimeException(setDataSource failed: status = 0x80000000)
    java.lang.RuntimeException(setDataSourceCallback failed: status = 0x80000000)
    java.lang.RuntimeException(setDataSourceCallback failed: status = 0x80000000)
    java.lang.RuntimeException(setDataSource failed: status = 0x80000000)
    java.lang.RuntimeException(setDataSource failed: status = 0x80000000)
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 6): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{DirectByteBuffer->Object->Drawable}, DATA_DISK_CACHE, https://ibb.co/WcJMjSw
    There were 2 root causes:
    java.lang.RuntimeException(setDataSourceCallback failed: status = 0x80000000)
    java.lang.RuntimeException(setDataSourceCallback failed: status = 0x80000000)
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->GifDrawable->Drawable}
        Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->Bitmap->BitmapDrawable}
    There was 1 root cause:
    java.lang.RuntimeException(setDataSourceCallback failed: status = 0x80000000)
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.lang.RuntimeException: setDataSourceCallback failed: status = 0x80000000
        Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->BitmapDrawable->Drawable}
    There was 1 root cause:
    java.lang.RuntimeException(setDataSourceCallback failed: status = 0x80000000)
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.lang.RuntimeException: setDataSourceCallback failed: status = 0x80000000
      Cause (2 of 6): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{FileInputStream->Object->Drawable}, DATA_DISK_CACHE, https://ibb.co/WcJMjSw
        Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->GifDrawable->Drawable}
        Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->Bitmap->BitmapDrawable}
        Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{FileInputStream->BitmapDrawable->Drawable}
      Cause (3 of 6): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{ParcelFileDescriptor->Object->Drawable}, DATA_DISK_CACHE, https://ibb.co/WcJMjSw
    There were 2 root causes:
    java.lang.RuntimeException(setDataSource failed: status = 0x80000000)
    java.lang.RuntimeException(setDataSource failed: status = 0x80000000)
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptor->Bitmap->BitmapDrawable}

解决方案

核心问题:使用的URL不是直接图片链接

从日志可见,你加载的https://ibb.co/WcJMjSw是图片分享页面地址,不是图片的直接资源链接。Glide只能解析图片文件的URL,无法解析网页内容,因此加载失败。

解决步骤

  1. 打开该分享页面,右键图片选择「复制图片地址」,或找到页面中的「Download」按钮,复制对应的直接下载链接(格式通常为https://i.ibb.co/xxxxxx/xxx.jpg这类指向图片文件的地址)
  2. 将review.userImage替换为这个直接图片URL

后续排查(若替换URL后仍有问题)

  • 检查网络权限:确认AndroidManifest.xml中已添加<uses-permission android:name="android.permission.INTERNET" />
  • 更新Glide版本:使用最新稳定版Glide,避免版本兼容问题
  • 清除Glide缓存:调用Glide.get(context).clearDiskCache()和Glide.get(context).clearMemory()清除缓存后重试
  • 验证图片格式:确保图片是Glide支持的格式(JPG、PNG、GIF等)

内容的提问来源于stack exchange,提问作者worrum

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 14:15:41