Property delegate must have a 'getValue(ChatActivity, KProperty<*>)' method. None of the following functions is suitable:

Viewed 3717
//getting an error in android studio when using lazy for getStringExtra

private val name : String by lazy {
    intent.getStringExtra(UID)
}

another class

enter image description here

 val intent = Intent(requireContext(),ChatActivity::class.java)
                      intent.putExtra(UID,id)
                      intent.putExtra(NAME,name)
                      intent.putExtra(IMAGE,photo)
                      startActivity(intent)
1 Answers

In Kotlin, you cannot assign Nullable types to Non-Nullable, getStringExtra returns String? which is not compatible with String

Try below

private val name : String? by lazy {
    intent.getStringExtra(UID)
}

or

private val name : String by lazy {
    intent.getStringExtra(UID)?:""
}
Related