Hi there i am very very new to programming but this is the error I am getting. Here is my code…
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
super.onRestoreInstanceState(savedInstanceState)
val savedString = savedInstanceState?.getString(TEXT_CONTENTS, “”)
editText2?.text = savedString
}
The final savedString expression I am getting the error “Required Editable! found String?”
I guess you are developing on android. The problem is that editText2?.text is of type Editable and not of type string so you can’t pass a string. I would take a look at Editable | Android Developers.
What you need to do as far as I can tell is
And FYI in the case of TextView you have to actually use setText method not setting it using “.text =” like you can with so many other bean properties because it has multiple overloads of setText and Kotlin decides that it is not a simple bean property.
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
super.onRestoreInstanceState(savedInstanceState)
val savedString = savedInstanceState?.getString(TEXT_CONTENTS, “”)
editText2?.text = savedString
}
Your are using a nullable string instead a not null string. If savedInstanceState is null, savedString will be null. So, if we add elvis operator and return a empty string, it would work.
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
super.onRestoreInstanceState(savedInstanceState)
val savedString = savedInstanceState?.getString(TEXT_CONTENTS, "") ?: ""
editText2?.text = savedString
}