java.lang.NullPointerException with boolean

后端 未结 4 1975
长情又很酷
长情又很酷 2020-12-01 21:01

I wrote a realy simple code based on another question and here it is:

It throws me an error

java.lang.NullPointerException line 5 and 17

<
4条回答
  •  鱼传尺愫
    2020-12-01 21:40

    You used the Boolean instead of boolean. Boolean is a class, which means you can assign objects to it. In your case, you passed in a null, which is then assigned to param. You then tried to use param, which of course resulted in a NullPointerException.

    You can:

    • Get rid of the line bool(null)
    • Change Boolean to boolean in the parameters for bool()
    • Add an else if for when param is null

提交回复
热议问题