use*_*868 3 java eclipse debugging
我在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;
}
Run Code Online (Sandbox Code Playgroud)
我在一行切换了一个断点:rep = Math.pow(K, 2) / distEuc(n1, n2);我以默认值运行调试器,它工作正常.
问题是,在某些时候rep变量需要一个值NaN,我需要一个条件断点才能理解为什么.
我像这样设置条件断点:
但是当我运行调试时,它会跳过断点并继续循环.
我做错了什么?我该如何解决?
谢谢!
那是因为rep在该行中仍然等于0.0:Double rep = 0.0;
您需要System.out.println("Répulsion : " + rep);在计算rep值后将条件断点放在,然后当执行在该行停止时,您将"Drop to Frame"再次执行该方法.
你也应该使用Double.isNaN(rep)或rep.isNaN()代替rep == Double.NaN.
| 归档时间: |
|
| 查看次数: |
515 次 |
| 最近记录: |