是否EditText.getText()曾经返回null? [英] Does EditText.getText() ever returns null?
问题描述
所有过网我看像 edittext.getText例子()。的toString()
。我看不到任何空检查。在文档我没有看到,会说,这将永远是空的陈述。
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.
不过,什么是观察说;这是否曾经返回null?
Still, what does the observations say; does this ever return null?
推荐答案
的getText()
将不会返回空
。所以在下面的方法没有机会NPE。在的getText
将返回空字符串,如果没有字符串,它是绝对不会空
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();
然而,的EditText本身可以是空
如果不正确初始化,因此,以下将触发NPE
However the edittext itself can be null
if not initialized properly, Hence the following will trigger NPE
editText.getText().toString();
这篇关于是否EditText.getText()曾经返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!