Alin
Alin

Reputation: 14571

.class file opens instead of .java while debugging

Current setup:

Whenever I debug and a file from MainProject is on focus (actually BranchProject has only graphic and xml layout changes) the Debug window opens a .class file which is read only. I want it to open the .java file so I can edit it directly.

Upvotes: 33

Views: 61041

Answers (9)

Mathi
Mathi

Reputation: 1

Most of the time it happens when specific source folder are not added in build path Sources tab.

Right-click on the Project in the Package-Explorer, click Build Path -> Configure Build Path -> Source Tab

Add the source folder if your project source folder is not there. Select Add folder -> select your project source folder specifically. Eg: project_name/src . Then Apply it and restart server.

Upvotes: 0

AntimoV
AntimoV

Reputation: 51

If you tried all above hints and it still doesn't work try this solution, it worked form me:

  1. Right-click on the Project in the Package-Explorer, click Build Path -> Configure Build Path...
  2. Select tab Order and Export
  3. select library that you can't reach code and then click on button Bottom
  4. Then click on Apply and Close

hope this can help you

Upvotes: 0

ataraxis
ataraxis

Reputation: 1562

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)

Upvotes: 1

Shivaramakrishna Agapu
Shivaramakrishna Agapu

Reputation: 127

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 :)

Upvotes: 1

Serg Kryvonos
Serg Kryvonos

Reputation: 4667

  1. Open main project properties -> Java Build Path -> Projects tab and add there projects the main project depend on.
  2. Switch to Order and Export tab and uncheck Android Dependencies
  3. Enjoy

Upvotes: 0

Seraphim's
Seraphim's

Reputation: 12768

I found a good solution for me here:

Using Android library in eclipse and jumping to class files instead of source file that is within eclipse workspace

Simply, select each library project your project depends on, and use Top or Up to move it above the projects outputs. Eg. move all library projects to the top.

Upvotes: 0

Graeme
Graeme

Reputation: 25864

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 :)

Upvotes: 6

Simulant
Simulant

Reputation: 20102

I think this depends on, how you set up the dependency in eclipse. You should set up your BranchProject to depend on the source-Files of your MainProject. If you depend on compiles Class-Files is obvious that the debugger opens the class files, because it does not know about the source files.

Upvotes: 0

Steven
Steven

Reputation: 615

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.

Upvotes: 60

Related Questions