【问题标题】:What's the fix for 'One type argument expected for Interface RequestListener<R : Any!> in Kotlin?Kotlin 中接口 RequestListener<R : Any!> 的“一种类型参数”的修复方法是什么?
【发布时间】:2019-07-23 09:05:53
【问题描述】:

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

Here's the actual shot from the 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()
            }

【问题讨论】:

    标签: android kotlin


    【解决方案1】:

    尝试将您的请求侦听器更改为:object : RequestListener&lt;Drawable&gt;

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

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

    请尝试查看此帖子以获得任何额外帮助:Glide callback after success in 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.
                                }
    

    【讨论】:

    • 还是不行,我已经用Drawable替换了GlideDrawable,因为GlideDrawable现在已经过时了,并且给出了一个未解决的错误,但是只使用Drawable就可以了...
    • 哇。它买了一个细微的差别,现在错误只在于object 和两个override 部分。它说 Object is not abstract and does not implement abstract memberoverride 之前的相同错误
    • 哇哦!你真的帮助我度过了这个朋友。有效。正如您所提到的,只需稍作调整,override 就完成了。还有dataSource: com.bumptech.glide.load.DataSource?(你可以更新它)。非常感谢。 :) (是的,Windows 是 Alt+Enter)
    【解决方案2】:

    试试这个,

    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)
    

    【讨论】:

    • 是的,谢谢...即使这需要一些调整(如该线程的第一个答案中所述)。 :)
    猜你喜欢
    • 1970-01-01
    • 2018-03-26
    • 2021-03-15
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 2016-01-25
    • 1970-01-01
    相关资源
    最近更新 更多