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

Unable to insert breakpoint Absent Line Number Information

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


当前回答

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

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

@PrepareForTest({XXXXX.class})

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

其他回答

不知道这是否仍然相关,也许另一个水手会发现这有用。

当已编译的类文件关闭调试标志时,将出现该消息。

在eclipse中,您可以通过前面提到的选项打开它,

窗口—>首选项—> Java—>编译器—>类文件生成:“添加行号属性生成类文件”

但是如果您有一个jar文件,那么您将得到编译后的输出。解决这个问题没有简单的方法。

如果您可以访问源代码并使用ant来获取jar文件,那么您可以如下所示修改ant任务。

  <javac  destdir="${build.destDir}" srcdir="${build.srcDir}" source="1.6" fork="true" target="${javac.target}" debug="on" debuglevel="lines,vars,source" deprecation="on" memoryInitialSize="512m" memoryMaximumSize="1024m" optimize="true"   >

快乐的调试. .

裁判: http://doc.sumy.ua/prog/Java/javanut/ch16_04.htm

检查/做以下事情:

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)清洁和建造项目。开始调试。

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

对于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");
   }
}

如果您确实指出了您正在使用的eclipse版本和技术(例如,Java JDT,或面向Java的AJDT,或c++ CDT),这将有所帮助。

在Java方面,我猜想您的“勾选编译器选项中的复选框”指的就是这个

在“窗口—>首选项—> Java—>编译器—>类文件生成”下,所有“类文件”生成选项都设置为True:

(1)添加可变属性, (2) addline number, (3)添加源文件名, (4)保存未使用的局部变量。

您的项目是否只在全局级别(windows Preferences)或在项目特定级别检查这些?

你确定打开的类(你试图在上面设置断点):

是您的源代码之一(并且不是来自第三方库) 是。java,而不是。class?

尝试清理所有内容并重新构建所有内容,检查潜在的jar冲突。

这里有详细的解释:

https://github.com/spring-projects/spring-ide/issues/78

只是为了将来参考,这是答案的相关部分(忽略引用Spring Boot应用程序的事实,在许多其他情况下行为是相同的):

Whenever you set a breakpoint in Eclipse/STS, the IDE tries to set the breakpoint in the VM if you launch an app. That is what happens in your case when you run the boot app in debug mode. For each class that gets loaded into the JVM, the IDE checks whether it needs to set a breakpoint or not. If it decides to set the breakpoint, the tries to do so (using the information from the breakpoint definition in the IDE, including its line number, since you usually set line breakpoints on a source file at a given line). This decision (whether to set the breakpoint on a given loaded class or not) checks the types that you set the breakpoint on, enclosing types, and inner classes. This makes sure that breakpoints for inner classes (even anonymous inner classes) are set to the JVM (and are not ignored). Spring Boot generates an inner class for your controller at runtime (this is the CGLIB generated inner class that appears in the error message). When the JVM loads that class, it tries to set the line number breakpoint of the enclosing type (for this inner class). Since the generated inner class doesn't have any line number information (it doesn't need to have line number information), setting the breakpoint fails for this inner class with the mentioned error message. When the IDE loads the enclosing type (your controller class itself), it also tries to set the line breakpoint and succeeds with that. This is visualized with the check marker on the breakpoint marker. Therefore you can safely ignore the error message that shows up. To avoid this error message to show up, you can go to the preferences (Java -> Debug) and disable "Warn when unable to install breakpoint due to missing line number attributes".