Unresolved reference: View

I am working on Kotlin project but I am blocked by error :“Unresolved reference: View”
here is my code:

package com.android.example.aboutme

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)


}

private fun addNickname(view: View) {

    //Inside the addNickname function, use findViewById()
    // to get a reference to the nickname_edit edit
    // text and the nickname_text text view.
    val editText = findViewById<EditText>(R.id.nickname_edit)
    val nicknameTextView = findViewById<TextView>(R.id.nickname_text)
    //Set the text in the nicknameTextView text view to the text that
    // the user entered in the editText, getting it from the text property.

    nicknameTextView.text = editText.text
    //Hide the nickname EditText view by setting the visibility property of editText to View.GONE.

    editText.visibility = View.GONE
    //Hide the DONE button by setting the visibility property to View.GONE.
    view.visibility = View.GONE

    // make the nickname TextView view visible by setting its
    nicknameTextView.visibility = View.VISIBLE




}

}

Yes I have the same problem, did you find a solution?

I have the same problem

@vogelkkt I suppose you are missing an import android.view.View.

2 Likes