Does EditText.getText() ever returns null?

后端 未结 7 865
粉色の甜心
粉色の甜心 2020-11-30 09:31

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 wil

7条回答
  •  情话喂你
    2020-11-30 10:03

    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();
    

提交回复
热议问题