Java.lang.ClassFormatError: Missing code attribute in a method that is not native or abstract in the class file class name

I know this question may seem silly since I cannot give a lot of information about it, but I think the problem should be some kind of mistake ...

I wrote a java program with NetBeans 7.1 that now gets this error when trying to run. 10 minutes ago it worked fine, and I didn’t change anything for the class to which the error relates

Could this be some kind of NetBeans error? Maybe this is a well-known problem?

+4
source share
6 answers

JDK says for ClassFormatError:

Thrown when a Java virtual machine tries to read a class file and determines that the file is garbled or otherwise cannot be interpreted as a class file.

The class file may be corrupt. I am going to make a standard expression of IT support. Have you tried restarting NetBeans?

Hope that helps

0
source

He also received this exception in NB 7.2.

  • "clean build" and restart NB failed.
  • updating NB with the latest updates and performing a “clean and build” also did not work.

So, I renamed the cache directory:

c:\Users\userabcd\AppData\Local\NetBeans\Cache\7.2\index\ 

started NB, waited for him to finish the "background scan" and clicked on "Debug project" and voila. From time to time the cache is distorted: - /

+5
source

I got this exception too. My solution was:

  • edit and save the specified class (.java file)
  • cleaning and assembly project
  • deployment on tomcat server
+2
source

I just happened to beta version of Netbeans 7.4.

Things I tried:

  • Restarting NetBeans.
  • Clean and build.
  • Disabling netbeans, renaming the cache directory, starting netbeans, and waiting for the scan to complete.

What worked for me:

  • Writing the source file and saving a meaningless change (insert a space).

I do not know why any of the other steps did not resolve the error. Maybe this would work if I did a clean and build after renaming the cache?

Its a very unpleasant situation to be in - I hope this helps someone (maybe the future for me?).

+2
source

Decision

  • Project properties
  • Assembly → Compilation
  • un-check: Compile on save
  • Cleaning and assembly

Notes

  • If you leave Compile on Save un-checked, you will no longer have this problem for this project.
  • If you take advantage of the compilation function when saving, you can reinstall the parameter after cleaning and assembling and continue working on your project as usual.
  • Compile on Save is designed to save time by constantly recompiling your .java files into .class files in the background while saving changes to the source code. Thus, when you create or run your project, most of the compilation work is already completed, which allows you to quickly launch and test your code, even for large projects.
  • NetBeans uses some fancy caching and versioning to not recompile the entire project every time you save the file. This is why the other solutions listed here are often used. they are ways to defeat this caching and versioning system when it occasionally fails, as it was above.
+2
source

The same thing happened with Netbeans 7.1. Work on a project that works great for several months. Now I changed the bean, which is saved with javax.persistence, and now this exception is thrown. Reverted my small changes, cleared and compiled the project, rebooted the entire system: there are still exceptions. The curious thing: the created .war works fine in Tomcat on another machine.


UPDATE :

Today I had a problem again and I couldn’t remember how to solve it, but I found this post again.;)

After half an hour, I found a solution: just change the value of the serialVersionUID property, serialVersionUID application, and then you can change the value to its original value and redeploy again → work. It seems that Tomcat holds this class somewhere deep inside - deleting working directories has not led to success.

0
source

Source: https://habr.com/ru/post/1414401/


All Articles