Home  >  Q&A  >  body text

spring-mvc - Java String The previous line can also output a value, but after entering the if, it becomes a null pointer.

As shown in the above two pictures, I passed in a decidedDistribute from the front desk. From the output, it can be seen that the decidedDistribute has a value passed in, and the value is still correct when the if statement is judged, but I don’t know why the if function is entered. After the field is entered, it becomes a null pointer, null is output, and a null pointer exception is reported in subsequent calls.
Please explain, thank you

曾经蜡笔没有小新曾经蜡笔没有小新2712 days ago474

reply all(5)I'll reply

  • 漂亮男人

    漂亮男人2017-05-17 10:10:18

    You see the error message and it has already jumped to the Distribute2 method. Why do you still post the content of the Distribute3 method?

    reply
    0
  • PHP中文网

    PHP中文网2017-05-17 10:10:18

    Call DEBUG to track it

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-17 10:10:18

    You add null when judging if, as follows:

    if(decidedistribute!=null && "查询".equals(decidedistribute)){
        ...
    }
    

    You try it

    reply
    0
  • 怪我咯

    怪我咯2017-05-17 10:10:18

    I agree with Xiao Yang vita’s answer. You have found the place where the wrong code reported the error.

    In your eclipse or other IDE, set the number of lines of code to display, otherwise you won’t even know where the error code is.
    In addition, the stack has printed out which line of which class has the error. You can click on the link to directly Jump to the error reporting location

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-17 10:10:18

    Found the problem, this is a web project, the second time the null output is actually loaded after the first load and redirection, and the second time no value is passed in, resulting in an error, so the first time the output is successful , I made an oversight and made a mistake. I’m sorry for wasting everyone’s time. Thank you for your help

    reply
    0
  • Cancelreply