Eclipse Build Error "A class file was not written. The project may be inconsistent, if so try refreshing this project and building it"

33,266

Solution 1

I had the same problem and here's how I solved it in the end: It turned out that the disc space on the drive where workspace resides was full.

Silly mistake but worth checking.

Solution 2

In my case, this was caused by the fact that the build output directories were owned by a different user, and Eclipse could not write into them.

Solution 3

I had the same issues, the following worked for me:

  1. Right click eclipse then running "as an Administrator"
  2. Click Project > Clean.

Solution 4

Clean your workspace by starting eclipse from the command line with the -clean argument :

eclipse -clean

See also How to run eclipse in clean mode? and what happens if we do so?

Solution 5

I solved this problem by running Eclipse as root.

Share:
33,266

Related videos on Youtube

Sammy Guergachi
Author by

Sammy Guergachi

Creative Coding.

Updated on August 03, 2022

Comments

  • Sammy Guergachi
    Sammy Guergachi almost 2 years

    I have been struggling with a very weird issue that has suddenly popped up on the latest version of Eclipse Classic (4.2.2).

    Everytime I try creating or refactoring a class or subclass in any of my projects (all Java) in my Eclipse workspace I get an error at the very top of my class that says

    A class file was not written. The project may be inconsistent, if so try refreshing this project and building it
    

    Again, this happens when I create new classes. And even when I rename current classes, then undo the renaming, its totally fine, but changing a single character in the name causes this error to happen for that specific class.

    I have Auto Build on, and I tried multiple times to clean and refresh every project as well as restart Eclipse entirely.

    I have literally no idea how to even start figuring out how to fix this. The solutions i've found through search didn't help, so i'm hoping I might find any clues here.

    • user1676075
      user1676075 about 11 years
      Did you try what it suggests, which is to right-click on your project and select "refresh" ?
    • Krumelur
      Krumelur about 11 years
      One very curious thing that has hit me a couple of times with Eclipse is a bug(or feature?) in Windows, where full path of a file exceeds some number of characters (512?). In this case, Eclipse will silently fail to write the file, but don't realize until later.
  • cubecubed
    cubecubed almost 9 years
    This does in fact answer the question. He was saying that the solution is to have some disk space on the drive where your workspace is, which is what solved my problem.
  • Aquarius Power
    Aquarius Power over 8 years
    Eclipse should check for storage space, that is so simple to do, instead of creating that error. This solved for me too, neither cleaning/rebuilding worked (of course). Out of complete despair, he asked for a solution and this is the solution, so this answers the question.
  • Markus Mitterauer
    Markus Mitterauer almost 6 years
    I also just had the problem (Eclipse 4.7.3a), and in my case the cause was that a directory within the output directory (/target) lay on a faulty SSD "sector". So neither Eclipse nor Windows could write to that directory, nor delete it (e.g. with clean). After 1,5hrs of CHKDSK it worked again.
  • Setherith
    Setherith over 4 years
    This worked for me, I copy a lot of code over manually from my customers workstation (long story), and try to match the folder structures up but some of the security settings coming across are muddled. So using Project -> Clean... from the menu resolved this for me!
  • rinilnath
    rinilnath almost 4 years
    Once we clean the workspace with command prompt "eclipse.bat" -clean, as the workspace opens I gave project clean and the error is gone. After that we can start as usual through start menu without any specific arguments to it.