All over the net I see examples like edittext.getText().toString()
. I do not see any null check. In docs I do not see any statement that would say that this will never be null.
Still, what does the observations say; does this ever return null?
getText() ever return null? @tsp your code will result in NPE in that case. Maybe the warning is really saying "the user might have typed the word, 'null'" into the edittext.
it actually returns Editable and not CharSequence but you can store it in a String variable by calling toString() on it.
It will return true if its empty/null.
getText()
will not return null
. So there is no chance for NPE in following method. the getText
will return empty string if there is no string, which is definitely not null
getText().toString();
However the edittext itself can be null
if not initialized properly, Hence the following will trigger NPE
editText.getText().toString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With