Kotlin on Android uresolved reference


#1

Hello, im new to programming and im taking one internet course about kotlin.

class MainActivity : AppCompatActivity() {

internal var toggleTitle: Boolean? = false
var textView: TextView? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    title = "Prepínač"

    val button = findViewById(R.id.button3) as Button
    button.setOnClickListener { prepni() }

    textView = findViewById(R.id.textView) as TextView
}

protected fun prepni() {
    if (toggleTitle!!) {
        toggleTitle = false
        textView!!.text = "Vyplo mi"
    } else {
        toggleTitle = true
        textView!!.text = "Zaplo mi"
    }
}

}

I have problem with

as Button

as textView it says Unresolved reference.