gpt4 book ai didi

android - 如何处理 Glide V4 中找不到图像的错误

转载 作者:行者123 更新时间:2023-11-29 18:29:50 25 4
gpt4 key购买 nike

我尝试在 Glide 中处理未找到图像 (404) 错误,但它无法编译:

Glide.with(this@ImageActivity)
.addDefaultRequestListener(
object:RequestListener<Drawable> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

}

)
.load(imageURL).apply(requestOptions)
.into(imageview)

但是编译器在 object:RequestListener 上引发此错误:

Type mismatch: inferred type is but RequestListener! was expected

最佳答案

如果要使用addDefaultRequestListener,则需要使用Any而不是Drawable

Glide.with(context).addDefaultRequestListener(object : RequestListener<Any> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: com.bumptech.glide.request.target.Target<Any>?, isFirstResource: Boolean): Boolean {
}

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

})

关于android - 如何处理 Glide V4 中找不到图像的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56845954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com