I have an EditText
and I'm setting an error into it or dismiss the error after text changes. However somehow I'm getting NPE when trying to access the EditText
from the afterTextChanged()
method.
phone_number_input.addTextChangedListener(object : TextWatcher() {
...
override fun afterTextChanged(s: Editable?) {
if (isValid(s.toString())
phone_number_input.error = null // <-- NPE happens here
else
phone_number_input.error = "Number is invalid"
}
})
It's not reproducing constantly, but for the last month there were dozens of crashes on different devices starting from Android 4.4.2 up to 6.0.1.
How can that happen? If Fragment
is destroyed, TextWatcher
shouldn't be called, right? How can it be prevented?