为什么Eclipse调试器给出错误“源未找到”看似没有理由? [英] Why does the Eclipse debugger give the error "Source not found" seemingly without reason?

查看:107
本文介绍了为什么Eclipse调试器给出错误“源未找到”看似没有理由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Eclipse中进行调试时,经常发生调试器崩溃,显示错误消息Source not found(下面是一个带有Edit Source Lookup Path的按钮)。我以前在网上搜索过这个问题的解释/解决方案,但没有发现任何帮助。

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.

但是,我现在已经弄清楚发生了什么我的情况:当逐行扫描代码时,出现错误,然后逐步执行运行代码块。我不知道这个术语,但是我猜想很多应用程序可能在某些时候进入待机模式,而当前没有任何代码正在运行。一个例子是等待鼠标点击的图形应用程序。在MouseListener方法的断点处停止,然后从其中退出(进入待机模式)会导致我的错误。

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.

我提供了一个MWE在这个问题的底部。当我在线上放置一个断点时,会发生错误。

I've supplied an MWE at the bottom of this question. The error occurs when I place a breakpoint at the line

System.out.println("You clicked!");

并使用F6(Step Over)逐行退出该方法。如果我在收听者的最后一行按F8(Resume)而不是F6,调试器不会崩溃,一切都很好。

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.

我的问题是:为什么Eclipse在这种情况下会发生如此严重的事情呢?我明白源代码中没有一行可以在下面的示例中离开监听器之后,程序控制可以说是走到,但是为什么不进入待机模式而不抱怨?我可以以某种方式停用此错误,以防止我的调试会话如此频繁地满足他们不及时的结束吗?或者我只需要记住按F8而不是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?

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);
    }
}


推荐答案

Eclipse不会崩溃您正在尝试进入一个方法,其中eclipse不知道在哪里找到源( *。java )文件,并通知您。这是如何告诉eclipse哪里看。转到

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

窗口 - > 首选项 - > Java - > 安装的JRE ,选择您正在使用的JRE,然后单击编辑

Window -> Preferences -> Java -> Installed JREs, select the JRE you are using and click Edit.

在其中,选择列表中的所有jar文件您可以看到并点击源附件...

There, select all of the jar files in the list you see and and click Source Attachment....

在显示的窗口中,选择fille src .zip ,它位于您的JDK文件夹中(如果在安装JDK时未取消选中)。在机器上我现在就是这样,那就是

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

C:\Program Files\Java\jdk1.7.0_07\ src.zip

保存所有更改(可能会重新启动eclipse),您将不会再看到该错误。

Save all your changes (possibly restart eclipse) and you won't see that error again.

这篇关于为什么Eclipse调试器给出错误“源未找到”看似没有理由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆