Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Eclipse debugger give the error "Source not found" seemingly without reason?

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.

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.

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!");

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.

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);
    }
}
like image 912
andreasdr Avatar asked Feb 16 '13 19:02

andreasdr


People also ask

How do I enable debug breakpoints in Eclipse?

To define a breakpoint in your source code, right-click in the left margin in the Java editor and select Toggle Breakpoint. Alternatively, you can double-click on this position. The Breakpoints view allows you to delete and deactivate Breakpoints and modify their properties.


1 Answers

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, select the JRE you are using and click Edit.

There, select all of the jar files in the list you see and and click 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

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.

like image 118
jlordo Avatar answered Sep 18 '22 23:09

jlordo