开发者

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

开发者 https://www.devze.com 2022-12-21 09:45 出处:网络
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 addition

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?


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.


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.


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.


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


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


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.


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


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.


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.


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.


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.


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.


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消