Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file "name of class"

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?

like image 860
Maik Avatar asked Dec 12 '22 01:12

Maik


2 Answers

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 :-/

like image 190
Houtman Avatar answered Feb 02 '23 01:02

Houtman


EDIT: Added Solution B below.

Solution A:

  1. Project Properties
  2. Build >> Compiling
  3. un-check: Compile on Save
  4. Clean and Build

Notes A:

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

Solution B:

  1. Create empty folder e. g. C:\Temp\mine
  2. Create a new shortcut for NetBeans with command line parameter in Target: "C:\Program Files\NetBeans 8.2\bin\netbeans64.exe" --userdir "C:\Temp\mine"
  3. When compile errors occur (ClassNotFoundException, MethodNotFoundException, etc...) delete C:\Temp\mine\var\cache

Notes B:

  • You'll lose all your NetBeans settings the first time.
  • Much easier to solve future compile errors caused by caching bugs.
  • Allows running multiple copies of NetBeans, one per userdir.
like image 34
Jonathan Avatar answered Feb 02 '23 00:02

Jonathan