我在 Eclipse 中有这段 Java 代码,我想对其进行调试。
这是代码:
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;
}
我在行切换了一个断点:rep = Math.pow(K, 2) / distEuc(n1, n2);
我以默认值运行调试器,它工作正常。
问题是在某个时刻rep
变量取一个值NaN
我需要一个条件断点才能理解原因。
我这样设置条件断点:
但是当我运行调试时,它会跳过断点并且循环继续进行。
我做错了什么?我该如何解决它?
Thanks!
那是因为rep
该行中仍然等于 0.0:Double rep = 0.0;
您需要在以下位置放置一个条件断点System.out.println("Répulsion : " + rep);
,计算后rep
值,然后当执行在该行停止时,您可以“跳到帧”以再次执行该方法。
您还应该使用Double.isNaN(rep)
or rep.isNaN()
代替rep == Double.NaN
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)