Lazy val giving error

intent.getStringExtra giving error in chatActivity .kt file

Replace your code with give snippet

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

intent.getStringExtra() retruns nullable string hence your are required to declare them nullable.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like