加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Eclipse Debugger不会在条件断点处停止

发布时间:2020-12-15 04:31:15 所属栏目:Java 来源:网络整理
导读:我在 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 Do
我在 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,我需要一个条件断点才能理解原因.

我像这样设置条件断点:

Conditional Breakpoint

但是当我运行调试时,它会跳过断点并继续循环.

我做错了什么?我该如何解决?

谢谢!

解决方法

那是因为在该行中rep仍然等于0.0:Double rep = 0.0;

在计算rep值之后,你需要在System.out.println(“Répulsion:”rep);中放置一个条件断点,然后当执行在该行停止时,你“Drop to Frame”再次执行该方法.

您还应该使用Double.isNaN(rep)或rep.isNaN()而不是rep == Double.NaN.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读