Java – eclipse debugger does not stop at a conditional breakpoint

I have this java code in eclipse and I want to debug it

This is the code:

public Double repulsion(Node n1,Node n2) {
    Double rep = 0.0;
    rep = Math.pow(K,2) / distEuc(n1,n2);
    System.out.println("Répulsion : " + rep);
    listForcesRep.add(rep);
    return rep;
}

    private Double distEuc(Node n1,Node n2) {
    Double d = 0.0;
    Object[] n1Attributes = n1.getAttribute("xy");
    Double x1 = (Double) n1Attributes[0];
    Double y1 = (Double) n1Attributes[1];
    Object[] n2Attributes = n2.getAttribute("xy");
    Double x2 = (Double) n2Attributes[0];
    Double y2 = (Double) n2Attributes[1];
    d = Math.sqrt((Math.pow(x1 - x2,2) + Math.pow(y1 - y2,2)));
    return d;
}

I switched a breakpoint on one line: rep = math pow(K,2)/ distEuc(n1,n2); I run the debugger by default and it works properly

The problem is that sometimes the rep variable takes the value Nan, and I need a conditional breakpoint to understand the reason

I set conditional breakpoints like this:

But when I run debugging, it skips the breakpoint and continues the loop

What did I do wrong? How can I solve it?

thank you!

Solution

That's because rep is still equal to 0.0 in this line: Double rep = 0.0;

After calculating the rep value, you need to out. println(“Répulsion:”rep); Place a conditional breakpoint in, and then when the execution stops on the line, you "drop to frame" execute the method again

You should also use double IsNaN (REP) or rep.isnan () instead of rep = = double NaN.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>