Nullpointer exception

前端 未结 5 1777
予麋鹿
予麋鹿 2020-12-02 01:05

There is a possiblity that this may be a dupicate question. I initialize a String variable to null.I may or may not update it with a value.Now I want to check whether this v

5条回答
  •  抹茶落季
    2020-12-02 01:19

    if you are checking whether "s" is null, then do not apply a dot(.) after "s". Doing that would throw NullPOinterException, as applying dot(.) means that you are trying to access on a pointer location which is basically null at the moment !

    Also try to use library functions that check whether a string is null or empty. you may use StringUtils.isEmpty(s) from apache library which checked both

提交回复
热议问题