Kotlin 中"接口请求侦听器<R 的一个类型参数:任何!>的修复是什么?



实际上我是 Kotlin 的新手,一直在做一个项目,严重卡在这个问题上,在发布这个问题之前,已经看了其他几篇文章和帖子,但没有一篇是有帮助的。

这是Android Studio的实际镜头。

这段代码有什么问题?另外,它说... onException overrides nothing. onResourceReady overrides nothing.

 Glide.with(this@SetupUserActivity).load(storedPhotoUrl)
                               .listener(object : RequestListener<String, Drawable> {
                                override fun onException(e: Exception?, model: String?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
                                    progress_bar_setup_user_img.visibility = View.GONE
                                    return false; }
                                override fun onResourceReady(resource: Drawable?, model: String?, target: Target<Drawable>?, isFromMemoryCache: Boolean, isFirstResource: Boolean): Boolean {
                                    progress_bar_setup_user_img.visibility = View.GONE
                                    return false
                                }
                            }).into(user_img_setup)
                }
            } catch (e: Exception) {
                e.printStackTrace()
            }

尝试将请求侦听器更改为以下内容:object : RequestListener<Drawable>

Glide.with(this@SetupUserActivity).load(storedPhotoUrl)
                               .listener(object : RequestListener<Drawable> {
.........

我认为您遇到这个问题的原因是您可能覆盖了错误RequestListener

尝试查看这篇文章以获取任何额外的帮助:在 Kotlin 中成功后滑行回调

您必须覆盖这些方法:

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.
                            }

试试这个,

Glide.with(this@SetupUserActivity).load(storedPhotoUrl)
        .listener(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.
            }
        }).into(user_img_setup)

相关内容

最新更新