F
F
foonfyrick2021-02-01 09:39:12
Java
foonfyrick, 2021-02-01 09:39:12

After leaving the fragment to the previous fragment and changing the orientation, the editText must not be null?

java.lang.IllegalStateException: fah_edtFname must not be null
From Fragment A I press the button and Fragment B opens, in it I save the values ​​​​of all EditText' s, when I flip the screen, everything typed is saved, but as soon as I return to Fragment A and change orientation screen, the error java.lang.IllegalStateException: fah_edtFname must not be null, (fah_edtFname is EditText), that is, if I go to Fragment B, then press the back arrow and it returns me to the previous Fragment A, and press change orientation, then being in fragment A, I get an error that in the closed fragment B, my edit texts are null ..

override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        val human = saveChangedText()
        outState.putParcelable("savedText",human)
    }
    fun saveChangedText():Human?{
            val firstName = fah_edtFname.text.toString()
            val lastName=fah_edtLastName.text.toString()
            val age =fah_edtAge.text.toString()
            val job = fah_edtJob.text.toString()
            return Human(first_name = firstName,last_name = lastName,age = age,job = job)
    }

I solved the error, I put a check - if the edit texts are not null, then save their text, but I don’t understand why, if the fragment is already closed, then I still try to work out onSaveInstanceState in it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question