在尝试设置断点时,我在Eclipse中得到这个奇怪的错误。

Unable to insert breakpoint Absent Line Number Information

我勾选了编译器选项的复选框,但运气不好。


当前回答

首先,我建议确定问题是与项目相关还是与单个测试文件相关。试着在调试模式下运行任何其他测试文件。

如果问题只适用于一个文件,这可能与自我嘲笑有关(就像我的情况一样)。否则,编译器/构建设置应该被更改。在之前的评论中已经描述过了。

我只是想强调一下。这已经足够我浪费时间在修复项目设置,而这是完全没有必要的:)

其他回答

如果上述解决方案不起作用,并且你在做了spring bean注入后开始遇到这个问题,问题可能是你没有为注入类使用接口。尝试使用实现接口的类进行注入可以解决这个问题。下面是一个例子: 无法安装用于创建bean的断点问题

有一次我在使用junit和Mockito时遇到了同样的错误,我忘记为静态类添加@PrepareForTest。

添加以下代码修复了我的问题。

@PrepareForTest({XXXXX.class})

不确定是不是同一个案子。

对于Spring相关的问题,考虑在某些情况下它生成的类“没有行号”;例如,一个没有接口的@Service注释类,添加接口就可以调试了。请参见这里的完整示例。

@Service("SkillService")
public class TestServiceWithoutInterface {
   public void doSomething() {
      System.out.println("Hello TestServiceWithoutInterface");
   }
}

上面的服务将有一个由spring生成的接口,导致“缺少行号”。添加一个真实的界面解决了生成问题:

public interface TestService {
    void doSomething();
}

@Service("SkillService")
public class TestServiceImpl implements TestService {
   public void doSomething() {
      System.out.println("Hello TestServiceImpl");
   }
}

我的情况与此类似:

我正在调试一个JUnit测试 我使用Mockito创建一个间谍,如在spyTask =间谍(new Task()) 我将断点放在我正在监视的类中(在Task.java中)

这个断点会生成问题中的错误,每次我运行Debug As…> JUnit测试

为了解决这个问题,我将断点“向上”移动到实际测试中(在TaskTest.java内部)。一旦执行停止,我将断点添加回原来的位置(在Task.java中)。

我仍然得到相同的错误,但点击“确定”后,断点工作正常。

希望这对大家有所帮助,

-gmale

We have very useful information to solve this problem already, but in my specific case, the problem was that as I did an update to my project from the repository, new classes were generated with the compiled source from the newest code. The problem is that I forgot to change the versions of the projects in my POM files and as the breakpoints were set on the new code and the POM files were still pointing to old versions that were available on the JAR files of a previous compilation, the classes from the JAR files were chosen and not the classes from the new code.

在恢复中,为了解决这个问题,我只需要更新主项目的POM文件的版本,清理并重新编译源代码,最后刷新环境。我希望这能对其他人有用。