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

Unable to insert breakpoint Absent Line Number Information

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


当前回答

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

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

@PrepareForTest({XXXXX.class})

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

其他回答

我在一个特定的项目中遇到了同样的问题,我一直试图重置窗口中的行号属性->首选项…然后我意识到每个项目都有自己的行号属性设置。右键单击项目,进入属性,选择JavaCompiler,并选中“添加行号属性…”

在eclipse菜单中,进入“窗口->首选项->Java->编译器” 取消标记复选框“添加行号属性…” 单击“应用”->是 标记复选框“添加行号属性…” 再次申请。 愉快调试

我的情况与此类似:

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

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

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

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

希望这对大家有所帮助,

-gmale

检查/做以下事情:

1)在“窗口—>首选项—> Java—>编译器—>类文件生成”下,所有选项必须为True:

(1) Add variable attributes...
(2) Add line number attributes...
(3) Add source file name...
(4) Preserve unused (never read) local variables

2)在项目的.settings文件夹中,找到一个名为org.eclipse.jdt.core.prefs的文件。 验证或设置org.eclipse.jdt.core.compiler.debug.lineNumber=generate

3)如果仍然出现错误窗口,单击复选框不显示错误信息。

4)清洁和建造项目。开始调试。

正常情况下,错误窗口不再显示,调试信息显示正确。

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文件的版本,清理并重新编译源代码,最后刷新环境。我希望这能对其他人有用。