Reputation: 4074
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);
}
}
Upvotes: 6
Views: 46000
Reputation: 21
The aim is to be able to open a .class file without a source
As the previous answer mentioned the decompiler on the marketplace fixed it for me. After installing, you then have to follow these instructions I found on - Mkyong.com
In Eclipse IDE. Clicks Window -> Preferences -> General -> Editors -> File Associations.
In File types section, select *.class without source.
Scroll down to the Associated editors section, select Class Decompiler Viewer, clicks Default button. If the Class Decompiler Viewer is missing, clicks Add button to add a new Class Decompiler Viewer. The key is to make this the default.
Click Apply and Close button.
Upvotes: 1
Reputation: 1
"Source not found" error can be resolved by providing the source of the class file i.e .java file so that it can navigate to the source file. Otherwise, you can go for a decompiler to open the .class file directly.
Go to Eclipse-->Help-->Eclipse MarketPlace -->Search for decompiler and install it.
Now, the issue can be resolved.
Upvotes: 0
Reputation: 37843
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.
Upvotes: 24
Reputation: 2606
goto window->preferences->java->installed jres and delete the jre, then do "add" and look for the JDK not the JRE!
Upvotes: 5