Nullpointer exception

前端 未结 5 1786
予麋鹿
予麋鹿 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:24

    If you use

    if (x == null)
    

    you will not get a NullPointerException.

    I suspect you're doing:

    if (x.y == null)
    

    which is throwing because x is null, not because x.y is null.

    If that doesn't explain it, please post the code you're using to test for nullity.

提交回复
热议问题