How to trace a NullPointerException in a chain of getters

后端 未结 11 1542
谎友^
谎友^ 2020-12-03 06:46

If I get a NullPointerException in a call like this:

someObject.getSomething().getSomethingElse().
    getAnotherThing().getYetAnotherObject().getValue();
         


        
11条回答
  •  自闭症患者
    2020-12-03 07:24

    In IntelliJ IDEA you can set exceptionbreakpoints. Those breakpoints fire whenever a specified exception is thrown (you can scope this to a package or a class).

    That way it should be easy to find the source of your NPE.

    I would assume, that you can do something similar in netbeans or eclipse.

    EDIT: Here is an explanation on how to add an exceptionbreakpoint in eclipse

提交回复
热议问题