java.lang.RuntimeException: Uncompilable source code - what can cause this?


Java Problem Overview

This error is just bizarre, my code compiles fine, I can see there are no problems with it, yet this error has just popped up. I have tried re-starting NetBeans and there is no additional exception information.

What can cause this?

Java Solutions

Solution 1 - Java

If it is Netbeans, try to uncheck "Compile on save" setting in the project properties (Build -> Compiling). This is the only thing which helped me in a similar situation.

Solution 2 - Java

I guess you are using an IDE (like Netbeans) which allows you to run the code even if certain classes are not compilable. During the application's runtime, if you access this class it would lead to this exception.

Solution 3 - Java

It's caused by NetBeans retaining some of the old source and/or compiled code in its cache and not noticing that e.g. some of the code's dependencies (i.e. referenced packages) have changed, and that a proper refresh/recompile of the file would be in order.

The solution is to force that refresh by either:

a) locating & editing the offending source file to force its recompilation (e.g. add a dummy line, save, remove it, save again),
b) doing a clean build (sometimes will work, sometimes won't),
c) disabling "Compile on save" (not recommended, since it can make using the IDE a royal PITA), or
d) simply remove NetBeans cache by hand, forcing the recompilation.

As to how to remove the cache:

If you're using an old version of NetBeans:

  • delete everything related to your project in .netbeans/6.9/var/cache/index/ (replace 6.9 with your version).

If you're using a newer one:

  • delete everything related to your project in AppData/Local/NetBeans/Cache/8.1/index/ (replace 8.1 with your version).

The paths may vary a little e.g. on different platforms, but the idea is still the same.

Solution 4 - Java

I also got the same error and I did clean build and it worked.

Solution 5 - Java

Add selenium-server-standalone-3.4.0.jar. It works to me. Download Link

Solution 6 - Java

Recheck the package declarations in all your classes!

This behaviour has been observed in NetBeans, when the package declaration in one of the classes of the package refers to a non-existent or wrong package. NetBeans normally detects and highlights this error but has been known to fail and misleadingly report the package as free of errors when this is not the case.

Solution 7 - Java

I had the same issue with one of my netbeans project.

Check whether you have correctly put the package name on all the classes. I got the same error message because i forgot to put the package name of a certain class (which was copied from another project).

Solution 8 - Java

Disable Deploy on Save in the Project's Properties/Run screen. That's what worked for me finally. Why the hell NetBeans screws this up is beyond me.

Note: I was able to compile the file it was complaining about using right-click in NetBeans. Apparently it wasn't really compiling it when I used Build & Compile since that gave no errors at all. But then after that, the errors just moved to another java class file. I couldn't compile then since it was grayed out. I also tried deleting the build and dist directories in my NetBeans project files but that didn't help either.

Solution 9 - Java

Organize your code as a maven module. Once done run the command from terminal
$mvn installl
to check if your code builds fine.
Finally import the project in netbeans or eclipse as maven project.

Solution 10 - Java

change the package of classes, your files are probably in the wrong package, happened to me when I copied the code from a friend, it was the default package and mine was another, hence the netbeans could not compile because of it.

Solution 11 - Java

I had this problem with NetBeans 8.0.1. Messages about problem in project deleted class. Deleting the ~/.netbeans didn't work. Also I looked for ANY reference to the deleted class in ALL my projects, nothing found. I deleted the build classes, everything. Then, when I started Netbeans again, compile and magically appears the message in Run and into the mother compiled class. I tried the uncheck "Compile on save" Dime solution, and works, but it's not practical. Finally, my solution was edit and force recompile of the mother class. This way the new .class doesn't contains the message and Run works OK.

Solution 12 - Java

Just check the packaging, the simplest answer I can provide is that your package has been mislabeled (within a class).

Also, you may have some weird characters. Try white-flushing the code in a Notepad (or Gedit) and then pasting it into a newly created class with your IDE.

Solution 13 - Java

If you are using Netbeans, try to hit the Clean and Build button, let it do the thing and try again. Worked for me!

Solution 14 - Java

I had the same problem. My error was the packaging. So I would suggest you first check the package name and if the class is in the correct package.

Solution 15 - Java

Implementing my own functional interfaces resolved this for me (so instead of using java.util.function.* just create your own single-method interface with the parameters and return-type you want).


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMalcomTuckerView Question on Stackoverflow
Solution 1 - JavaDimeView Answer on Stackoverflow
Solution 2 - JavaChandra SekarView Answer on Stackoverflow
Solution 3 - JavakommradHomerView Answer on Stackoverflow
Solution 4 - JavaUVMView Answer on Stackoverflow
Solution 5 - JavaNadeeshani WilliamView Answer on Stackoverflow
Solution 6 - JavaIqbalHamidView Answer on Stackoverflow
Solution 7 - JavachandimaView Answer on Stackoverflow
Solution 8 - JavaMichael KView Answer on Stackoverflow
Solution 9 - JavaEnrico GiurinView Answer on Stackoverflow
Solution 10 - JavaKleytonView Answer on Stackoverflow
Solution 11 - JavaRogelio TriviñoView Answer on Stackoverflow
Solution 12 - Java3xCh1_23View Answer on Stackoverflow
Solution 13 - JavaAshtezView Answer on Stackoverflow
Solution 14 - JavaMeluleki DubeView Answer on Stackoverflow
Solution 15 - JavaNathan CrauseView Answer on Stackoverflow