.class file opens instead of .java while debugging

When you're using a Library project one of the things you're in fact doing is compiling your Library project into a jar and then referencing that jar in your calling Project.

If you right click the Project, and select "Configure Build Path" you'll see a tab called "Libraries", if you look inside "Android Dependencies" you'll notice a list of jar's corresponding to your Library projects.

These jars are expandable, showing you that they have a slot for a source attachment. Usually this would be editable allowing you to directly link the source but in terms of ADT these are already filled and are uneditable.

When debugging these files you're linked to a read-only class file with this attached source. This is because you're not running against source files directly, you're running against a pre-compiled class file. Until the ADT team get this functionality in place, you're pretty much forced to jump to the direct source code and rebuild everything.

EDIT

See @Steven linked answer :)


Skyler's answer from this post worked for me: Opening source code from debug view edits .class after Android R18 update

Here is a summary: The fix is to right click the Project name in the debug view, and select "Edit Source Lookup..." from the menu. From there, remove the Default lookup path. After that, manually add the associated projects (not jars) that your project references. This is done by clicking Add, selecting Java Project, then checking the appropriate projects.


The problem is that the class file is preferred over the java (by default), here is how you can change that for Eclipse (tested on NEON 2):

  1. Right-click on the Project in the Project-Explorer, click Properties
  2. On the new window select: Run/Debug Settings
  3. Create a new configuration (or duplicate another one)
  4. Select the new config and click Edit...
  5. Go to the tab Source
  6. Select the Default and Remove
  7. Create a new path with Add..., select Java Library, then JRE System Library
  8. Create a new path with Add..., select the location where the sourcecode is by Workspace folder (if it is a project in the same workspace) or File System directory (it it is not)

I faced the same issue while debugging the a .java file using Eclipse IDE. As per my understanding this issue comes when we put the xyz.class file of xyz.java file or JAR at the project build path. Delete the .class or JAR file from the project class path and rerun .java file in the debug mode. This time you see a source not found window. Click on "Source not found" button and check "Find duplicates..." at the bottom of the window. Done your problem is solved :)

Tags:

Eclipse