I have this Java Code in Eclipse that I would like to Debug.
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 toggled a breakpoint at line : rep = Math.pow(K, 2) / distEuc(n1, n2); and I ran the debugger in its default values and it works fine.
The thing is that at some point the rep variable takes a value NaN and I need a conditional breakpoint in order to understand why.
I set the conditional breakpoint like this :

But when I run the debug, it skips the breakpoint and the loop keeps on going.
What did I do wrong? And how can I fix it?
Thanks!
That's because rep is still equals to 0.0 in that line: Double rep = 0.0;
You need to put a conditional breakpoint at System.out.println("Répulsion : " + rep);, after calculating rep value, then when execution stops at that line, you "Drop to Frame" to execute again that method.
You should also use Double.isNaN(rep) or rep.isNaN() instead of rep == Double.NaN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With