Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchFieldError Java

Tags:

java

debugging

I am getting a NoSuchFieldError in my code, now oracle isn't very clear about why this error is thrown only saying: this error can only occur at run time if the definition of a class has incompatibly changed.

Can someone explain to me how one could 'incompatibly change' a class? The class I am talking about extends quite allot of classes so I suspect it might have to do with that but I don't know where to start looking or what I'm looking for.

like image 713
Timotheus Avatar asked Jul 13 '11 23:07

Timotheus


1 Answers

This error is typically thrown if you only partially recompile your code. You've got old code that is referencing a field that no longer exists in the recompiled class files.

The solution is to clean out all the class files and compile everything from fresh.

Update: If you still get the same error after recompiling everything, then you're probably compiling against one version of an external library and using another at runtime.

What you need to do now is first identify the class that is causing the problem (it looks like you have done this already) and then run your application with the -verbose:class command line option. It will dump a lot of class loading information on your standard out and you'll be able to find out where the problematic class is exactly loaded from.

like image 182
biziclop Avatar answered Oct 03 '22 06:10

biziclop