Tandoh Anthony Nwi-Ackah
Tandoh Anthony Nwi-Ackah

Reputation: 2175

None of the following candidates is responsible because of the receiver type mismatch

Working on an android project everything is working fine until now. Getting this error

None of the following candidates is responsible because of the receiver type mismatch. It occurs on the id of my views.

The below is the code

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

    }

Upvotes: 2

Views: 6119

Answers (2)

Tandoh Anthony Nwi-Ackah
Tandoh Anthony Nwi-Ackah

Reputation: 2175

Thanks guys. Have solve the issue. I added .view to the extension.

Wrong

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

Correct

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

Upvotes: 1

AlexTa
AlexTa

Reputation: 5251

Just inflate your view using LayoutInflater instead of inflate from View.

Replace this line:

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

By:

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

Upvotes: 0

Related Questions