为什么 Eclipse 调试器会给出错误“找不到源"?看似无缘无故? [英] Why does the Eclipse debugger give the error "Source not found" seemingly without reason?

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

问题描述

当我在 Eclipse 中调试时,经常会发生调试器崩溃的情况,显示错误消息找不到源"(其下方是一个带有编辑源查找路径"文本的按钮).我之前在网上搜索过这个问题的解释/解决方案,但没有找到对我有帮助的.

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(恢复")而不是 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

Window -> Preferences -> Java -> Installed JREs,选择你正在使用的 JRE 并点击编辑.

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

在那里,选择您看到的列表中的所有 jar 文件,然后单击 Source Attachment....

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

在出现的窗口中,选择位于 JDK 文件夹中的 src.zip 文件(如果您在安装 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 FilesJavajdk1.7.0_07src.zip.

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

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

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

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