When I'm debugging in Eclipse, it often happens that the debugger crashes, displaying the error message "Source not found" (under which is a button with the text "Edit Source Lookup Path"). I have previously searched the web for an explanation/solution to this problem, but found nothing of help to me.
当我在Eclipse中调试时,经常发生调试器崩溃,显示错误消息“Source not found”(其下是一个带有“Edit Source Lookup Path”文本的按钮)。我之前在网上搜索过这个问题的解释/解决方案,但对我没有任何帮助。
However, I've now figured out what is happening in my case: The error occurs when stepping through the code line by line, and then stepping out of a block of running code. I don't know the terminology, but I guess many applications might enter "standby mode" at some point, where none of its code is currently running. One example is a graphical application waiting for a mouse click. Stopping at a breakpoint in a MouseListener method, and then stepping out of it (into "standby mode") will cause the error in my case.
但是,我现在已经弄清楚在我的情况下发生了什么:当逐行单步执行代码,然后逐步退出运行代码块时,会发生错误。我不知道术语,但我猜许多应用程序可能会在某些时候进入“待机模式”,其中当前没有任何代码正在运行。一个示例是等待鼠标单击的图形应用程序。在MouseListener方法中停止断点,然后退出它(进入“待机模式”)将导致我的错误。
I've supplied an MWE at the bottom of this question. The error occurs when I place a breakpoint at the line
我在这个问题的底部提供了一个MWE。当我在该行放置断点时发生错误
System.out.println("You clicked!");
and step out of the method line by line using F6 ("Step Over"). If I press F8 ("Resume") instead of F6 at the last line of the listener, the debugger doesn't crash and everything is fine.
并使用F6逐步退出方法(“Step Over”)。如果我在侦听器的最后一行按F8(“Resume”)而不是F6,调试器不会崩溃,一切都很好。
My question is: why does Eclipse do something so severe as to crash in this case? I understand that there is no line in the source code that the program control can be said to "step to" after leaving the listener in the below example, but why not just go into "standby mode" without complaining? Can I deactivate this error somehow, to prevent my debugging sessions from so frequently meeting their untimely end? Or do I just have to remember to press F8 instead of F6 when the latter would cause a crash?
我的问题是:为什么Eclipse在这种情况下会做一些如此严重的崩溃?据我所知,源代码中没有一行可以说程序控件在下面的示例中离开监听器后可以说“步入”,但为什么不进入“待机模式”而不抱怨?我可以以某种方式停用此错误,以防止我的调试会话经常遇到不合时宜的结束吗?或者我只需要记住按F8而不是F6,后者会导致崩溃?
package app;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
public class TestFrame extends JFrame {
public TestFrame() {
getContentPane().setPreferredSize(new Dimension(200, 200));
getContentPane().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("You clicked!");
}
});
pack();
}
public static void main(String[] args) {
JFrame testFrame = new TestFrame();
testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
testFrame.setVisible(true);
}
}
2 个解决方案
#1
21
Eclipse doesn't crash. You're trying to step into a method, where eclipse doesn't know where to find the source (*.java
) files and informs you about this. Here is how to tell eclipse where to look. Go to
Eclipse不会崩溃。您正试图进入一个方法,其中eclipse不知道在哪里找到源(* .java)文件并通知您。这是如何告诉eclipse在哪里看。去
Window -> Preferences -> Java -> Installed JREs, select the JRE you are using and click Edit.
窗口 - >首选项 - > Java - >已安装的JRE,选择您正在使用的JRE,然后单击编辑。
There, select all of the jar files in the list you see and and click Source Attachment....
在那里,选择您看到的列表中的所有jar文件,然后单击Source Attachment ....
In the window that shows up, select the fille src.zip
, which is in your JDK folder (if you didn't uncheck it while installing the JDK). On the machine I'm on right now, that is
在显示的窗口中,选择fille src.zip,它位于JDK文件夹中(如果在安装JDK时未取消选中它)。在我现在的机器上,就是这样
C:\Program Files\Java\jdk1.7.0_07\src.zip
.
C:\ Program Files \ Java \ jdk1.7.0_07 \ src.zip。
Save all your changes (possibly restart eclipse) and you won't see that error again.
保存所有更改(可能重新启动eclipse),您将不会再次看到该错误。
#2
2
goto window->preferences->java->installed jres and delete the jre, then do "add" and look for the JDK not the JRE!
转到window-> preferences-> java->安装jres并删除jre,然后执行“添加”并查找JDK而不是JRE!
#1
21
Eclipse doesn't crash. You're trying to step into a method, where eclipse doesn't know where to find the source (*.java
) files and informs you about this. Here is how to tell eclipse where to look. Go to
Eclipse不会崩溃。您正试图进入一个方法,其中eclipse不知道在哪里找到源(* .java)文件并通知您。这是如何告诉eclipse在哪里看。去
Window -> Preferences -> Java -> Installed JREs, select the JRE you are using and click Edit.
窗口 - >首选项 - > Java - >已安装的JRE,选择您正在使用的JRE,然后单击编辑。
There, select all of the jar files in the list you see and and click Source Attachment....
在那里,选择您看到的列表中的所有jar文件,然后单击Source Attachment ....
In the window that shows up, select the fille src.zip
, which is in your JDK folder (if you didn't uncheck it while installing the JDK). On the machine I'm on right now, that is
在显示的窗口中,选择fille src.zip,它位于JDK文件夹中(如果在安装JDK时未取消选中它)。在我现在的机器上,就是这样
C:\Program Files\Java\jdk1.7.0_07\src.zip
.
C:\ Program Files \ Java \ jdk1.7.0_07 \ src.zip。
Save all your changes (possibly restart eclipse) and you won't see that error again.
保存所有更改(可能重新启动eclipse),您将不会再次看到该错误。
#2
2
goto window->preferences->java->installed jres and delete the jre, then do "add" and look for the JDK not the JRE!
转到window-> preferences-> java->安装jres并删除jre,然后执行“添加”并查找JDK而不是JRE!