【问题标题】:None of the following candidates is responsible because of the receiver type mismatch由于接收器类型不匹配,以下候选人均不负责
【发布时间】:2017-07-11 09:22:55
【问题描述】:

到目前为止,在一个 android 项目上工作一切正常。 收到此错误

由于接收器类型不匹配,以下候选人均不负责。 它发生在我的视图的 id 上。

下面是代码

override fun getView(postion: Int, p1: View?, p2: ViewGroup?): View {
        val myView = View.inflate(con, R.layout.item, null)
        val Tanamo = this.lis[postion]
        myView.txt1.text = Tanamo.Title
        myView.txt2.text = Tanamo.Author


        myView.but!!.setBackgroundResource(android.R.drawable.ic_media_play)

        myView.but.setOnClickListener({

            if (playRadio) {
                playRadio = false
                medi!!.stop()
                myView.but!!.setBackgroundResource(android.R.drawable.ic_media_play)
            } else {
                playRadio = true
                medi = MediaPlayer()

                try {
                    medi!!.setDataSource(Tanamo.Url)
                    medi!!.prepare()
                    medi!!.start()
                    myView.but!!.setBackgroundResource(android.R.drawable.ic_media_pause)
                } catch (ex: Exception) {
                }
            }


        })

        return myView

    }

【问题讨论】:

  • 请发布完整的堆栈跟踪。

标签: android kotlin


【解决方案1】:

谢谢各位。 有解决问题。 我在扩展中添加了 .view。

错误

import kotlinx.android.synthetic.main.item.*

正确

   import kotlinx.android.synthetic.main.item.view.*

【讨论】:

  • 我与这个小疏忽斗争了一段时间。如此简单的事情会引起很多悲伤。 (我认为您应该将此答案标记为正确)
【解决方案2】:

只需使用 LayoutInflater 扩展您的视图,而不是使用 View 扩展。

替换这一行:

val myView = View.inflate(con, R.layout.item, null)

作者:

val myView = LayoutInflater.from(con).inflate(R.layout.item, null)

【讨论】:

    猜你喜欢
    • 2021-09-27
    • 1970-01-01
    • 2021-05-11
    • 2020-10-18
    • 2019-04-19
    • 2022-06-12
    • 2021-10-21
    • 1970-01-01
    • 2020-07-20
    相关资源
    最近更新 更多