Whats means this java-error: "java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf- in the context of hibernate?

I'm getting a NoSuchMethodError error when running my Java program. What's wrong and how do I fix it?

Replay

Without any more information it is difficult to pinpoint the problem, but the root cause is that you most likely have compiled a class against a different version of the class that is missing a method, than the one you are using when running it.

Look at the stack trace ... If the exception appears when calling a method on an object in a library, you are most likely using separate versions of the library when compiling and running. Make sure you have the right version both places.

If the exception appears when calling a method on objects instantiated by classes you made, then your build process seems to be faulty. Make sure the class files that you are actually running are updated when you compile.

I feel your pain. You can learn programming out of a book, but when it comes to working with Eclipse or Visual Studio, its a ^&^&'n nightmare to do something simple like add a library. Everybody expects you to know how to use it and if you don't they downvote your question. The problem is, if you don't work in an office or know anyone who you can ask these questions, then its almost impossible to figure this stuff out. Anyway...

I was having your problem, and this is how I fixed it. The following steps are a working way to add a library. I had done the first two steps right, but I hadn't done the last one by dragging the ".jar" file direct from the file system into the "lib" folder on my eclipse project. Additionally, I had to remove the previous version of the library from both the build path and the "lib" folder.

If anyone knows of a more proper way to add/update a library, please chime in.

Step 1 - Add .jar to build path

Whats means this java-error: "java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf- in the context of hibernate?

Step 2 - Associate sources and javadocs (optional)

Whats means this java-error: "java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf- in the context of hibernate?

Step 3 - Actually drag .jar file into "lib" folder (not optional)

Whats means this java-error: "java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf- in the context of hibernate?

Note that in the case of reflection, you get an NoSuchMethodException, while with non-reflective code, you get NoSuchMethodError. I tend to go looking in very different places when confronted with one versus the other.

If you have access to change the JVM parameters, adding verbose output should allow you to see what classes are being loaded from what JARs.

java -verbose:class <other args>

When your program is run, the JVM should dump to standard out information such as:

...

[Loaded junit.framework.Assert from file:/C:/Program%20Files/junit3.8.2/junit.jar]

...

This is usually caused when using a build system like Apache Ant that only compiles java files when the java file is newer than the class file. If a method signature changes and classes were using the old version things may not be compiled correctly. The usual fix is to do a full rebuild (usually "ant clean" then "ant").

Sometimes this can also be caused when compiling against one version of a library but running against a different version.

This can also be the result of using reflection. If you have code that reflects on a class and extracts a method by name (eg: with Class.getDeclaredMethod("someMethodName", .....)) then any time that method name changes, such as during a refactor, you will need to remember to update the parameters to the reflection method to match the new method signature, or the getDeclaredMethod call will throw a NoSuchMethodException.

If this is the reason, then the stack trace should show the point that the reflection method is invoked, and you'll just need to update the parameters to match the actual method signature.

In my experience, this comes up occasionally when unit testing private methods/fields, and using a TestUtilities class to extract fields for test verification. (Generally with legacy code that wasn't designed with unit testing in mind.)

If you are writing a webapp, ensure that you don't have conflicting versions of a jar in your container's global library directory and also in your app. You may not necessarily know which jar is being used by the classloader.

e.g.

  • tomcat/common/lib
  • mywebapp/WEB-INF/lib

If using maven or another framework, and you get this error randomly almost, try "clean install", especially if you wrote the object and you know it has the method. Worked for me.

To answer the original question.

According to java docs here

"NoSuchMethodError" Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.

Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.

!) if it happens in the run time, check the class containing the method is in class path. 2) Check if you have added new version of jar and the method is compatible.

I ran into a similar problem when I was changing method signatures in my application. Cleaning and rebuilding my project resolved the "NoSuchMethodError".

These problems are caused by the use of the same object at the same two classes. Objects used does not contain new method has been added that the new object class contains.

ex:

filenotnull=/DayMoreConfig.conf
16-07-2015 05:02:10:ussdgw-1: Open TCP/IP connection to SMSC: 10.149.96.66 at 2775
16-07-2015 05:02:10:ussdgw-1: Bind request: (bindreq: (pdu: 0 9 0 [1]) 900 900 GEN 52 (addrrang: 0 0 2000) )
Exception in thread "main" java.lang.NoSuchMethodError: gateway.smpp.PDUEventListener.<init>(Lgateway/smpp/USSDClient;)V
        at gateway.smpp.USSDClient.bind(USSDClient.java:139)
        at gateway.USSDGW.initSmppConnection(USSDGW.java:274)
        at gateway.USSDGW.<init>(USSDGW.java:184)
        at com.vinaphone.app.ttn.USSDDayMore.main(USSDDayMore.java:40)

-bash-3.00$

These problems are caused by the concomitant 02 similar class (1 in src, 1 in jar file here is gateway.jar)

If your file name is different than the class name which contain main method then it may be the possibility that this error may cause.

Category: java Time: 2008-08-29 Views: 131

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.171 (s). 12 q(s)