问题
I know this question may seems stupid since i cannot give a lot of infos about it, but I think that the problem has to be some kind of bug...
I have written a java program whith NetBeans 7.1, which now gets me this error when trying to run. 10 mins ago it was perfectly running, and i have changed nothing to the class the error refers to
Could this be some kind of NetBeans error? Maybe it is a well know problem?
回答1:
The JDK says for ClassFormatError:
Thrown when the Java Virtual Machine attempts to read a class file and determines that the file is malformed or otherwise cannot be interpreted as a class file.
Perhaps a class file has become corrupted. I am going to do the standard IT support statement. Have you tried restarting NetBeans?
Hope that helps
回答2:
It also got this exception in NB 7.2
- 'clean an build' and restarting NB didn't work
- updating NB with the latest updates and performing 'clean and build' also didn't work.
So i renamed the cache directory:
c:\Users\userabcd\AppData\Local\NetBeans\Cache\7.2\index\
started NB, waited for it to finish 'background scanning' and pressed 'Debug project' and voila. The cache gets corrupted every once in a while :-/
回答3:
I got also this exception. My solution was:
- edit and save mentioned class (.java file)
- clean & build project
- deploy to tomcat server
回答4:
I just had this happen to me with Netbeans 7.4 Beta.
Things I tried:
- Restarting Netbeans.
- Clean and build.
- Shutting down netbeans, renaming the cache dir, starting netbeans and waiting for scanning to complete.
What worked for me:
- Making the source file writable and saving a meaningless change (inserting a space).
I don't know why any of the other steps didn't fix the error. Maybe it would have worked if I had done a clean and build after renaming the cache dir?
Its a very frustrating situation to be in - Hopefully this helps someone (perhaps a future me?).
回答5:
Solution:
- Project Properties
- Build >> Compiling
- un-check: Compile on Save
- Clean and Build
Notes:
- If you leave Compile on Save un-checked, you won't have this problem any longer for this project.
- If you enjoy the benefits of the Compile on Save feature, you can re-check the option after you clean and build, and continue work on your project as normal.
- Compile on Save is meant to save time by constantly recompiling your .java files into .class files in the background as you save changes to your source code. That way when you build or run your project, most of the compiling work has already been completed allowing you to run and test your code quickly, even for large projects.
- NetBeans uses some fancy caching and versioning to avoid having to recompile your entire project every time you save a file. That's why the other solutions listed here will often work; they are ways of defeating this caching-and-versioning system when it occasionally fails, as it has above.
回答6:
Got right the same thing with Netbeans 7.1. Working on a project that works fine for several months. Now I changed a bean which gets persisted with javax.persistence and now this exception got thrown. Reverted my few changes, clean and compile the project, reboot the whole system: still exceptions. The curious thing about it: the generated .war works perfectly in a Tomcat at another machine.
UPDATE:
Today I got the same problem again and I couldn't recall how to solve it, but I found this post again. ;)
After a half hour I found the solution: Just change value of the property serialVersionUID
, redeploy the app and then you can change the value to its original value and redeploy again -> working.
Seems like Tomcat is holding that class somewhere deep inside – deleting working directories didn't led to success.
来源:https://stackoverflow.com/questions/10757216/java-lang-classformaterror-absent-code-attribute-in-method-that-is-not-native-o