18

I have an issue with Eclipse 3.6 (Helios) :

Anytime I want to generate a serial version ID (serialVersionUID) for a class that extends a serializable class, I get the following message :

The following error occured : Could not find class file. Make sure the file is compilable.

What am I doing wrong ?

Thank you.

Tity
  • 201
  • 1
  • 3
  • 4

11 Answers11

16

In my case, I've solved this problem by the following way:

Right click the project, "Build Path" -> "Configure Build Path" -> "Source" tab, remove paths tagged "missing".

Po Zhou
  • 595
  • 1
  • 5
  • 17
5

Sometimes a tool (AspectJ - AJDT for instance or another) removes the Java Nature of the project, and it doesn't compile while it doesn't show any error on the editor.

Check that you have a .project file that contains both entries : org.eclipse.jdt.core.javabuilder and org.eclipse.jdt.core.javanature

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>Myproject</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
            <!-- This one is required -->
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>

        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>

            <!-- This one is required too -->
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    </natures>
</projectDescription>
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Marc Le Bihan
  • 2,308
  • 2
  • 23
  • 41
3

There is a bug issiue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=259506

Aside of modifing .project file as Marc has stated, Andrew Eisenberg suggested to try closing and openiong project again.

Using both helped in my case.

EDIT: Some time ago I moved to eclipse with integrated AspectJ Development Tools. Since then I have avaiable options for aspectJ which work every time.

enter image description here

Bolesław Denk
  • 553
  • 7
  • 15
2

If you have any build problems( errors ), eclipse will give

   Could not find class file. Make sure the file is compilable.

error. Make sure their are no problems with your build path(like... Missisng class folders/jars ).

Ben
  • 1,571
  • 1
  • 13
  • 29
madhu_karnati
  • 785
  • 1
  • 6
  • 22
2

Eclipse use the org.eclipse.jdt.core.javabuilder-Builder to locate the .class-Files. But either the Builder did not start or did not found the .class-files.

Reduce the .project-File to

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>yourprojectsname</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

Remove all of maven's build-path entries.

Add the Maven nature.

Thats all.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Grim
  • 1,938
  • 10
  • 56
  • 123
1

In my case also I used ,

Right click the project, "Build Path" -> "Configure Build Path" -> "Source" tab, remove paths tagged "missing". Though I am not sure will it impact the project dependencies on any thing.

1

I had the same problem. This has worked for me:

  1. Go to tab Navigator: Window > Show View > Navigator
  2. Right Click on Project
  3. Build Project

Try generate serial version ID again

1

Go to:

Window > Show View > Other..

Select:

General > Problems

You can see all the Eclipse problems which include jar dependencies. My issue was that I was missing a required jar file. Once I added that jar file, the issue got fixed.

Lewis Nakao
  • 7,079
  • 2
  • 26
  • 21
0

Check if auto build is on. The class file is required to generate serial version UID. If not build the project and try again.

wizneel
  • 301
  • 1
  • 2
  • 10
0

In my case, I had multiple projects in my eclipse workspace. The solution is to first fix all your current project's errors, then go to "Problems" view and either fix or delete all Errors there.

Now if you re-execute the eclipse quickfix "Add generated serial version ID" it should work fine.

0

In my case (I'm using Maven), I had to delete one of the dependencies in the local repository because it had become corrupted. Look for errors about problem reading dependency jars.

Damo
  • 47
  • 1
  • 9