我如何修复诺舒德罗?

发布于 2025-01-27 23:02:45 字数 70 浏览 3 评论 0原文

在运行我的Java程序时,我会收到nosuchmethoderror错误。怎么了,我该如何解决?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

惜醉颜 2025-02-03 23:02:45

没有更多信息,很难查明问题,但是根本原因是您很可能已经针对缺少方法的类别的类别的类别编译了一个类,而不是您在运行它时使用的方法。

查看堆栈跟踪...如果在库中调用对象上的方法时出现异常,则在编译和运行时,您很可能会使用库的单独版本。确保您都有正确的版本。

如果在通过类实例化的对象上调用方法时出现异常,则您的构建过程似乎是错误的。编译时,请确保您实际运行的类文件会更新。

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.

水染的天色ゝ 2025-02-03 23:02:45

我遇到了您的问题,这就是我解决的问题。以下步骤是添加库的一种工作方式。我已经正确完成了前两个步骤,但是我没有通过将“ .jar”文件直接从文件系统拖动到我的Eclipse项目上的“ lib”文件夹中完成了最后一个步骤。此外,我必须从构建路径和“ lib”文件夹中删除库的先前版本。

步骤1-添加.jar到构建路径

“在此处inter

步骤2-关联源和Javadocs(可选)

“在此处输入图像说明”

步骤3-实际上将.jar文件拖动到“ lib”文件夹(不是可选)

“在此处输入图像说明”

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.

Step 1 - Add .jar to build path

enter image description here

Step 2 - Associate sources and javadocs (optional)

enter image description here

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

enter image description here

巾帼英雄 2025-02-03 23:02:45

请注意,在反思的情况下,您会得到nosuchmethodexception,而对于非反射代码,您可以获得nosuchmethoderror。当面对一个与另一个相对于另一个时,我倾向于在非常不同的地方看。

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.

花开半夏魅人心 2025-02-03 23:02:45

如果您可以访问更改JVM参数,则添加详细输出应使您可以查看正在加载哪些JAR文件的类。

java -verbose:class <other args>

运行程序时,JVM应倾倒以标准信息,例如:

...

[已加载junit.framework.assert从文件:/c:/program%20files/junit3.8.2/junit.jar]

...

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

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]

...

救星 2025-02-03 23:02:45

如果使用 maven 或其他框架,并且几乎可以随机遇到此错误,请尝试使用干净的安装...

clean install

如果您编写对象并且您知道它具有该方法,则尤其有可能工作。

If using Maven or another framework, and you get this error almost randomly, try a clean install like...

clean install

This is especially likely to work if you wrote the object and you know it has the method.

皓月长歌 2025-02-03 23:02:45

这通常是在使用

有时,这也可能是针对一个版本的库时,但要与其他版本进行竞争时会引起。

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.

不必了 2025-02-03 23:02:45

我有同样的错误:

  Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonGenerator.writeStartObject(Ljava/lang/Object;)V
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:151)
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
        at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3681)
        at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3057)

要解决它,我首先检查了, 单击您的POM组合 - &gt; ctrl+alt+shift+shift+u右键单击您的pom - &gt; maven-maven-&gt; show依赖关系 )了解图书馆之间的冲突到底在哪里(Intelij Idea)。在我的特殊情况下,我有不同版本的杰克逊依赖性。

”在此处输入图像描述”

1)因此,我直接在项目的POM中明确添加了这两个版本的最高版本-2.8.7。

在属性中:

<jackson.version>2.8.7</jackson.version>

和作为依赖性:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>${jackson.version}</version>
</dependency>

2),但也可以使用依赖项排除

按照与以下相同的原则:

  <dependency>
      <groupId>group-a</groupId>
      <artifactId>artifact-a</artifactId>
      <version>1.0</version>
          <exclusions>
             <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
             </exclusion>
         </exclusions>
  </dependency>

依赖性版本的依赖性将被排除在您的项目之外。

I had the same error:

  Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonGenerator.writeStartObject(Ljava/lang/Object;)V
        at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:151)
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
        at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3681)
        at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3057)

To solve it I checked, firstly, Module Dependency Diagram (click in your POM the combination -> Ctrl+Alt+Shift+U or right click in your POM -> Maven -> Show dependencies) to understand where exactly was the conflict between libraries (Intelij IDEA). In my particular case, I had different versions of Jackson dependencies.

enter image description hereenter image description here

1) So, I added directly in my POM of the project explicitly the highest version - 2.8.7 of these two.

In properties:

<jackson.version>2.8.7</jackson.version>

And as dependency:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>${jackson.version}</version>
</dependency>

2) But also it can be solved using Dependency Exclusions.

By the same principle as below in example:

  <dependency>
      <groupId>group-a</groupId>
      <artifactId>artifact-a</artifactId>
      <version>1.0</version>
          <exclusions>
             <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
             </exclusion>
         </exclusions>
  </dependency>

Dependency with unwanted version will be excluded from your project.

狼性发作 2025-02-03 23:02:45

为什么有人不提依赖性冲突?这个常见问题可能与包含不同版本的依赖罐有关。
详细的说明和解决方案: https://dzone.com/articles/solvice.com/articles/solving-dependence-dependency-dependency--------冲突中的冲突

简短答案;

添加此Maven依赖性;

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
    <rules>
        <dependencyConvergence />
    </rules>
</configuration>
</plugin>

然后运行此命令;

mvn enforcer:enforce

也许这是您面临的问题。

Why anybody doesn't mention dependency conflicts? This common problem can be related to included dependency jars with different versions.
Detailed explanation and solution: https://dzone.com/articles/solving-dependency-conflicts-in-maven

Short answer;

Add this maven dependency;

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
    <rules>
        <dependencyConvergence />
    </rules>
</configuration>
</plugin>

Then run this command;

mvn enforcer:enforce

Maybe this is the cause your the issue you faced.

謌踐踏愛綪 2025-02-03 23:02:45

如果您正在撰写WebApp,请确保您的集装箱全局库目录中的JAR和应用程序中都没有相互矛盾的版本。您可能不一定知道Class Loader正在使用哪个JAR。

例如

  • tomcat/common/lib
  • mywebapp/web-inf/lib

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
夕色琉璃 2025-02-03 23:02:45

对我来说,这是因为我更改了函数中的参数类型,从对象a,字符串a。我可以用干净并再次建造解决

For me it happened because I changed argument type in function, from Object a, to String a. I could resolve it with clean and build again

网白 2025-02-03 23:02:45

就我而言,我有一个多模块项目,场景就像com.xyz.testclass在模块a以及模块b中。模块a取决于模块b。因此,当创建一个汇编罐时,我认为如果没有调用方法,我认为只保留了一个类的类别,那么我得到了nosuchmethoderror runtime>运行时异常,但是汇编很好。

相关: https://reflectoring.io/nosuchmethod/

In my case I had a multi module project and scenario was like com.xyz.TestClass was in module A and as well as in module B and module A was dependent on module B. So while creating a assembly jar I think only one version of class was retained if that doesn't have the invoked method then I was getting NoSuchMethodError runtime exception, but compilation was fine.

Related : https://reflectoring.io/nosuchmethod/

暗喜 2025-02-03 23:02:45

这也可能是使用反射的结果。如果您的代码反映了类并按名称提取方法(例如:with class.getDeclaredMethod(“ somemethodname”,.....)),那么任何时间都会更改该方法名称,例如就像在重构期间一样,您需要记住将参数更新为反射方法以匹配新方法签名,或者getDeclaredMethod呼叫将抛出nosuchmethodexception

如果这是原因,则堆栈跟踪应显示调用反射方法的观点,您只需要更新参数即可匹配实际方法签名。

以我的经验,当单元测试私人方法/字段以及使用Testutilitys类提取字段以进行测试验证时,这偶尔会出现。 (通常使用未考虑单位测试设计的旧代码。)

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

浅忆 2025-02-03 23:02:45

这意味着同类中不存在各自的方法:

  1. 如果您使用的是JAR,则反复编译并检查各自版本的JAR是否具有适当的类。
  2. 检查您是否已经从源头编译了适当的类。

It means the respective method is not present in the class:

  1. If you are using jar then decompile and check if the respective version of jar have proper class.
  2. Check if you have compiled proper class from your source.
城歌 2025-02-03 23:02:45

我刚刚通过重新启动日食并运行应用程序来解决此错误。
我的案件的原因可能是因为我在不关闭项目或Eclipse的情况下更换源文件。
这引起了我正在使用的不同类别的类别。

I have just solved this error by restarting my Eclipse and run the applcation.
The reason for my case may because I replace my source files without closing my project or Eclipse.
Which caused different version of classes I was using.

段念尘 2025-02-03 23:02:45

尝试这样做:删除项目目录下的所有.class文件(当然,所有子目录)。重建。

有时,MVN Clean(如果使用Maven)不会清洁。.class文件由javac手动创建。这些旧文件包含旧签名,导致nosuchmethoderror

Try this way: remove all .class files under your project directories (and, of course, all subdirectories). Rebuild.

Sometimes mvn clean (if you are using maven) does not clean .class files manually created by javac. And those old files contain old signatures, leading to NoSuchMethodError.

揽月 2025-02-03 23:02:45

只是增加了现有答案。我在Eclipse中与Tomcat面对这个问题。我已经更改了一个课程,并做了以下步骤,

  1. 在Eclpise

    中清理并构建

  2. mvn Clean selplins intastion

  3. 安装中,

我仍然面临相同的错误。然后,我清洁了tomcat,清洁的tomcat工作目录和重新启动的服务器,我的问题已经消失了。希望这对某人有帮助

Just adding to existing answers. I was facing this issue with tomcat in eclipse. I had changed one class and did following steps,

  1. Cleaned and built the project in eclpise

  2. mvn clean install

  3. Restarted tomcat

Still I was facing same error. Then I cleaned tomcat, cleaned tomcat working directory and restarted server and my issue is gone. Hope this helps someone

写下不归期 2025-02-03 23:02:45

这些问题是由于在同一两个类中使用相同对象引起的。
所使用的对象不包含新方法,即新对象类包含。

例如:

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$ 

这些问题是由伴随02类似类引起的(src中的1,jar文件中的1个是gateway.jar)

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)

早茶月光 2025-02-03 23:02:45

回答原始问题。根据java文档

如果应用程序试图调用类的指定方法(静态或实例),并且该类不再具有该方法的定义。

通常,此错误被编译器捕获。只有当类的定义不兼容时,此错误才能在运行时间发生。

  1. 如果在运行时间内发生,请检查包含该方法的类位于类路径中。
  2. 检查您是否添加了JAR的新版本,并且该方法兼容。

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.

  1. 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.
嗼ふ静 2025-02-03 23:02:45

我通过重命名Junit测试文件解决了Eclipse的问题。
在我的日食工作空间中,我有一个应用程序项目和一个测试项目。
测试项目将应用程序项目作为构建路径上的必需项目。

开始获得Nosuchmethoderror。
然后,我意识到测试项目中的课程与应用程序项目中的类具有相同的名称。

App/  
  src/
     com.example/  
       Projection.java
Test/  
  src/
     com.example/
       Projection.java

将测试重命名为正确的名称“ PropentTest.java”之后,例外消失了。

I fixed this problem in Eclipse by renaming a Junit test file.
In my Eclipse work space I have an App project and a Test project.
The Test project has the App project as a required project on the build path.

Started getting the NoSuchMethodError.
Then I realized the class in the Test project had the same name as the class in the App project.

App/  
  src/
     com.example/  
       Projection.java
Test/  
  src/
     com.example/
       Projection.java

After renaming the Test to the correct name "ProjectionTest.java" the exception went away.

離人涙 2025-02-03 23:02:45

Nosuchmethoderror:我花了几个小时来解决此问题,最后通过重命名包装名称,清洁和构建来修复它。它应该修复。祝你好运。

NoSuchMethodError : I have spend couple of hours fixing this issue, finally fixed it by just renaming package name , clean and build ... Try clean build first if it doesn't works try renaming the class name or package name and clean build...it should be fixed. Good luck.

一梦等七年七年为一梦 2025-02-03 23:02:45

当我在应用程序中更改方法签名时,我遇到了类似的问题。
清洁和重建我的项目解决了“ Nosuchmethoderror”。

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

夏雨凉 2025-02-03 23:02:45

上面的答案很好地解释了..添加一件事
如果使用Eclipse使用Ctrl+Shift+T,然后输入类的软件包结构(例如:Gateway.smpp.pdueventlistener),您将在目前的所有罐子/项目中找到所有罐子/项目。从类路径中删除不必要的罐子或在类路径中添加。现在,它将选择正确的一个。

Above answer explains very well ..just to add one thing
If you are using using eclipse use ctrl+shift+T and enter package structure of class (e.g. : gateway.smpp.PDUEventListener ), you will find all jars/projects where it's present. Remove unnecessary jars from classpath or add above in class path. Now it will pick up correct one.

小兔几 2025-02-03 23:02:45

我遇到了类似的问题。

Caused by: java.lang.NoSuchMethodError: com.abc.Employee.getEmpId()I

最后,我确定了根本原因是更改变量的数据类型。

  1. lightee.java - &gt;包含其数据类型已从int更改为string的变量(empid)。
  2. reportgeneration.java - &gt;使用getter,getempid()检索值。

我们应该仅包括修改后的类,来重新启动罐子。由于reportgeneration.java i仅在JAR文件中包含employee.class。我必须在JAR中包括reportgeneration.class文件才能解决问题。

I ran into similar issue.

Caused by: java.lang.NoSuchMethodError: com.abc.Employee.getEmpId()I

Finally I identified the root cause was changing the data type of variable.

  1. Employee.java --> Contains the variable (EmpId) whose Data Type has been changed from int to String.
  2. ReportGeneration.java --> Retrieves the value using the getter, getEmpId().

We are supposed to rebundle the jar by including only the modified classes. As there was no change in ReportGeneration.java I was only including the Employee.class in Jar file. I had to include the ReportGeneration.class file in the jar to solve the issue.

も让我眼熟你 2025-02-03 23:02:45

我遇到了同样的问题。这也是当课程含糊不清时引起的。我的程序试图调用一种在同一位置 /类路径中存在的两个JAR文件中存在的方法。删除一个JAR文件或执行您的代码,以便仅使用一个JAR文件。检查您是否使用相同的JAR或不同版本的同一JAR包含同一类的罐子。

disp_e_exception [step] [] [z-java-105

I've had the same problem. This is also caused when there is an ambiguity in classes. My program was trying to invoke a method which was present in two JAR files present in the same location / class path. Delete one JAR file or execute your code such that only one JAR file is used. Check that you are not using same JAR or different versions of the same JAR that contain the same class.

DISP_E_EXCEPTION [step] [] [Z-JAVA-105 Java exception java.lang.NoSuchMethodError(com.example.yourmethod)]

蓝天 2025-02-03 23:02:45

大多数时间java.lang.nosuchmethoderror被捕获为编译器,但有时可能会在运行时发生。如果此错误在运行时发生,那么唯一的原因可能是使其不相容的类结构的更改。

最佳解释: https://wwww.journaldev.com/wwwww.journaldev.com/14538/14538/java-java-java-nang-nang-nosung-nosuchmetermetermetermetermeterorrerrorrer

Most of the times java.lang.NoSuchMethodError is caught be compiler but sometimes it can occur at runtime. If this error occurs at runtime then the only reason could be the change in the class structure that made it incompatible.

Best Explanation: https://www.journaldev.com/14538/java-lang-nosuchmethoderror

橙幽之幻 2025-02-03 23:02:45

我也遇到了这个错误。

我的问题是,我更改了方法的签名,类似的

void invest(Currency money){...}

方法

void invest(Euro money){...}

是从类似于

public static void main(String args[]) {
    Bank myBank = new Bank();

    Euro capital = new Euro();
    myBank.invest(capital);
}

编译器的环境中调用的,这在警告/错误方面是沉默的,因为资本既是货币又是欧元。

出现问题是因为我仅编译了定义该方法的类 - 银行,而不是从中调用该方法的类,其中包含main()方法。

这个问题不是您可能经常遇到的问题,因为大多数项目经常进行人工重建或自动触发构建操作,而不仅仅是编译一个修改的类。

我的用户酶是我生成了一个.jar文件,该文件将用作热五个文件,该文件不包含App.Class,因为它没有被修改。当我保留最初的论点的基类槽继承时,我不包括它是有意义的。

事实是,当您编译类时,结果字节码是 static ,换句话说,这是 hard-reference

原始的拆卸字节码(由Javap工具生成)看起来像这样:

 #7 = Methodref          #2.#22         // Bank.invest:(LCurrency;)V

ClassLoader加载新的编译银行。Class.Class。它找不到这样的方法,看起来好像是被删除并没有更改,因此命名错误。

希望这会有所帮助。

I've encountered this error too.

My problem was that I've changed a method's signature, something like

void invest(Currency money){...}

into

void invest(Euro money){...}

This method was invoked from a context similar to

public static void main(String args[]) {
    Bank myBank = new Bank();

    Euro capital = new Euro();
    myBank.invest(capital);
}

The compiler was silent with regard to warnings/ errors, as capital is both Currency as well as Euro.

The problem appeared due to the fact that I only compiled the class in which the method was defined - Bank, but not the class from which the method is being called from, which contains the main() method.

This issue is not something you might encounter too often, as most frequently the project is rebuilt mannually or a Build action is triggered automatically, instead of just compiling the one modified class.

My usecase was that I generated a .jar file which was to be used as a hotfix, that did not contain the App.class as this was not modified. It made sense to me not to include it as I kept the initial argument's base class trough inheritance.

The thing is, when you compile a class, the resulting bytecode is kind of static, in other words, it's a hard-reference.

The original disassembled bytecode (generated with the javap tool) looks like this:

 #7 = Methodref          #2.#22         // Bank.invest:(LCurrency;)V

After the ClassLoader loads the new compiled Bank.class, it will not find such a method, it appears as if it was removed and not changed, thus the named error.

Hope this helps.

少女净妖师 2025-02-03 23:02:45

在我的情况下,问题是在构建路径中有两个版本的同一库。库的较旧版本没有功能,而较新的版本则没有。

The problem in my case was having two versions of the same library in the build path. The older version of the library didn't have the function, and newer one did.

痴意少年 2025-02-03 23:02:45

我使用Intelij的Gradle项目也有类似的问题。
我通过删除.gradle(请参阅下面的屏幕截图)包裹并重建项目来解决它。
。gradle package

I had a similar problem with my Gradle Project using Intelij.
I solved it by deleting the .gradle (see screenshot below) Package and rebuilding the Project.
.gradle Package

你另情深 2025-02-03 23:02:45

我遇到了同样的问题。我更改了一种方法的返回类型,并运行了该类别的测试代码。那是我面对这个nosuchmethoderror的时候。作为解决方案,在再次运行测试代码之前,我在整个存储库上运行了Maven。在下一个单一测试运行中解决了问题。

I had faced the same issue. I changed the return type of one method and ran the test code of that one class. That is when I faced this NoSuchMethodError. As a solution, I ran the maven builds on the entire repository once, before running the test code again. The issue got resolved in the next single test run.

地狱即天堂 2025-02-03 23:02:45

在使用Quarkus时,我通过删除目标折线并重新启动程序解决了问题。

I solved the problem when using Quarkus by removing the target-folder and restart the program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文