即使 jar/类具有特定方法,我们什么时候会收到 java.lang.NoSuchMethodError

发布于 2024-07-25 17:36:09 字数 3177 浏览 14 评论 0原文

我正在使用 IText 库来促进小程序中的 pdf 导出。 在导出调用期间,它失败并出现以下错误:

java.lang.NoSuchMethodError: com.lowagie.text.pdf.PdfPTable.completeRow()V

我在 JD Decompiler 中打开了 Itext jar/PdfPtable.class 并确认该类已将completeRow 作为公共方法。

有人可以解释当 java.lang.NoSuchMethodError 抛出时可能出现的情况,即使 jar/class 有它吗?

这是堆栈跟踪; 可能不是很有帮助,因为大多数调用都是我们的应用程序特定的。

导出到 CSV 文件时出错 - java.lang.NoSuchMethodError: com.lowagie.text.pdf.PdfPTable.completeRow()V
com.blox.table.action.ExportToCSVAction.actionPerformed(ExportToCSVAction.java:193)
javax.swing.AbstractButton.fireActionPerformed(来源未知)
javax.swing.AbstractButton$Handler.actionPerformed(来源未知)
javax.swing.DefaultButtonModel.fireActionPerformed(来源未知)
javax.swing.DefaultButtonModel.setPressed(来源未知)
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(来源未知)
java.awt.Component.processMouseEvent(来源未知)
javax.swing.JComponent.processMouseEvent(来源未知)
java.awt.Component.processEvent(来源未知)
java.awt.Container.processEvent(来源未知)
java.awt.Component.dispatchEventImpl(来源未知)
java.awt.Container.dispatchEventImpl(来源未知)
java.awt.Component.dispatchEvent(来源未知)
java.awt.LightweightDispatcher.retargetMouseEvent(来源未知)
java.awt.LightweightDispatcher.processMouseEvent(来源未知)
java.awt.LightweightDispatcher.dispatchEvent(来源未知)
java.awt.Container.dispatchEventImpl(来源未知)
java.awt.Window.dispatchEventImpl(来源未知)
java.awt.Component.dispatchEvent(来源未知)
java.awt.EventQueue.dispatchEvent(来源未知)
java.awt.EventDispatchThread.pumpOneEventForFilters(来源未知)
java.awt.EventDispatchThread.pumpEventsForFilter(来源未知)
java.awt.EventDispatchThread.pumpEventsForHierarchy(来源未知)
java.awt.EventDispatchThread.pumpEvents(来源未知)
java.awt.EventDispatchThread.pumpEvents(来源未知)
java.awt.EventDispatchThread.run(来源未知)
com.lowagie.text.pdf.PdfPTable.completeRow()V
com.blox.table.view.GridTableModel$PdfExportWriter.writeNewLine(GridTableModel.java:7259)
com.blox.table.view.GridTableModel.buildExportData(GridTableModel.java:3111)
com.blox.table.view.GridTableModel.export(GridTableModel.java:2541)
com.blox.table.view.GridTable.export(GridTable.java:1318)
com.blox.table.action.ExportToCSVAction.exportToFile(ExportToCSVAction.java:248)
com.blox.table.action.ExportToCSVAction.access$1(ExportToCSVAction.java:245)
com.blox.table.action.ExportToCSVAction$Worker.exportToCSVFile(ExportToCSVAction.java:111)
sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)
sun.reflect.NativeMethodAccessorImpl.invoke(来源未知)
sun.reflect.DelegatingMethodAccessorImpl.invoke(来源未知)
java.lang.reflect.Method.invoke(来源未知)
spin.Initation.evaluate(Initation.java:175)
spin.off.SpinOffEvaluator$1.run(SpinOffEvaluator.java:108)
java.lang.Thread.run(来源不明)

I am using IText library to facilitate pdf export in an applet. During the export call it fails with following error:

java.lang.NoSuchMethodError: com.lowagie.text.pdf.PdfPTable.completeRow()V

I opened the Itext jar/PdfPtable.class in JD Decompiler and confirmed that the class has completeRow as a public method.

Can somebody explain the possible scenarios when a java.lang.NoSuchMethodError is thrown even when jar/class has it?

Here is the stack trace; may not be very helpful as most of the calls are our application specific.

Error while exporting to the CSV file - java.lang.NoSuchMethodError: com.lowagie.text.pdf.PdfPTable.completeRow()V
com.blox.table.action.ExportToCSVAction.actionPerformed(ExportToCSVAction.java:193)
javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
javax.swing.DefaultButtonModel.setPressed(Unknown Source)
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
java.awt.Component.processMouseEvent(Unknown Source)
javax.swing.JComponent.processMouseEvent(Unknown Source)
java.awt.Component.processEvent(Unknown Source)
java.awt.Container.processEvent(Unknown Source)
java.awt.Component.dispatchEventImpl(Unknown Source)
java.awt.Container.dispatchEventImpl(Unknown Source)
java.awt.Component.dispatchEvent(Unknown Source)
java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
java.awt.Container.dispatchEventImpl(Unknown Source)
java.awt.Window.dispatchEventImpl(Unknown Source)
java.awt.Component.dispatchEvent(Unknown Source)
java.awt.EventQueue.dispatchEvent(Unknown Source)
java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
java.awt.EventDispatchThread.pumpEvents(Unknown Source)
java.awt.EventDispatchThread.pumpEvents(Unknown Source)
java.awt.EventDispatchThread.run(Unknown Source)
com.lowagie.text.pdf.PdfPTable.completeRow()V
com.blox.table.view.GridTableModel$PdfExportWriter.writeNewLine(GridTableModel.java:7259)
com.blox.table.view.GridTableModel.buildExportData(GridTableModel.java:3111)
com.blox.table.view.GridTableModel.export(GridTableModel.java:2541)
com.blox.table.view.GridTable.export(GridTable.java:1318)
com.blox.table.action.ExportToCSVAction.exportToFile(ExportToCSVAction.java:248)
com.blox.table.action.ExportToCSVAction.access$1(ExportToCSVAction.java:245)
com.blox.table.action.ExportToCSVAction$Worker.exportToCSVFile(ExportToCSVAction.java:111)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
spin.Invocation.evaluate(Invocation.java:175)
spin.off.SpinOffEvaluator$1.run(SpinOffEvaluator.java:108)
java.lang.Thread.run(Unknown Source)

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

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

发布评论

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

评论(10

弄潮 2024-08-01 17:36:10

可能是类路径中出现了不同的版本,或者自编译类以来该特定方法的签名已更改

It could be that a different version appears in your classpath or that the signature of that particular method has changed since your compiled your class

哎呦我呸! 2024-08-01 17:36:10
  1. 通常,如果您的类路径中存在另一个版本的违规类,该版本早于您用于编译的版本(以及您之前所说的反编译版本),则通常会导致此类问题。 这种情况经常发生,因为类路径问题很常见,对于专家来说也是如此,尤其是专家。 在容器中,加载库的顺序未指定。

    假设您在 IDE 中使用 iText 1.a 并进行编译。 然后,将应用程序部署到预安装了 iText 1.b 的某个容器中。 当 b < 时,预安装的库优先。 a 那么你就会遇到这种问题。

    在您的情况下,没有容器,但您可能在打包/部署期间混合库版本,或者有不同的类路径用于开发和执行。

  2. 该 jar 在运行时不在类路径中,仅在编译时位于类路径中。 但是,当第一次访问 iText 时,您会得到一个 NoClassDefFoundError ,但事实并非如此。

  3. 如果 iText 本身会错过第三方库,那么在调用需要不满足依赖项的方法时,您也会收到 NoClassDefFoundError

    如果 iText 本身会错过第三方库,您也会收到一个 NoClassDefFoundError 错误

  1. Usually such problems are cause if there is another version of the offending class in your classpath before the version that you used for compile (and that you decompiled as said before). This happens often as classpath issues are common, also with experts, esp. in containers, where the order of loaded libraries is unspecified.

    So lets say you use iText 1.a to in your IDE and you compile against. Then you deploy your application into some container, where iText 1.b is preinstalled. Preinstalled libraries take precedence and when b < a then you run into this kind of problem.

    In your case there is no container, but you could mix up library versions during packaging/deployment or have different classpaths for development and execution.

  2. The jar is not in the classpath at runtime, only at compile time. But then you would get a NoClassDefFoundError when iText is accessed for the first time, which is not the case.

  3. If iText itself would miss a third party library you would also get a NoClassDefFoundError when calling the method that needs the unsatisfied dependency.

情话难免假 2024-08-01 17:36:10

我发现其中一个第三方 jar 捆绑了旧版本的 iText 库

I found out that one of the third party jar was bundling a older version of iText library

无力看清 2024-08-01 17:36:10

这意味着类 PdfPTable 的两个版本位于类路径中。 您使用的两个 jar 文件可能打包了同一类的不同版本。 简单的解决方法是对类路径中的 jar 文件执行 jar -tf 操作,然后使用 grep 查找您的类名。 删除过时的版本或更改类路径中 jar 文件的顺序。

That means two versions of the class PdfPTable are in your class path. Two jar files that you are using might have packaged different versions of the same class. Easy way to figure out is to do a jar -tf on the jar files in the classpath, and grep for your classname. Either remove the stale version or change the order of jar files in your class path.

泅人 2024-08-01 17:36:10

我使用的是 netbeans IDE,有时也遇到过这个问题。 例如,当我更改方法的参数时,它不再起作用了! 无意间我明白了,改变方法后,如果我右键单击该项目并按“清理”,就没有问题了!

I am using netbeans IDE and I had this problem some times. for example when I changed the parameters of a method, it didn't work anymore! Accidentally, I understood that after changing the method, if I right click on the project and press "clean", there were no problem anymore!

羞稚 2024-08-01 17:36:10

我遇到了同样的问题,我点击了“清理并构建项目”按钮,现在一切正常。 也许有时问题是由以前的构建造成的,您需要重建。

I had the same problem and I hit the Clean and Build Project button and everything works great now. Maybe sometimes the problem is stuck from previous builds and you need to rebuild.

何以畏孤独 2024-08-01 17:36:10

也可能是您的小程序类路径中出现了两个版本的 jar,并且加载的版本与编译代码时使用的版本具有不同的签名

It could also be that two versions of the jar appear in your applet classpath and the one that got loaded has a different signature than the one that your code was compiled with

巷雨优美回忆 2024-08-01 17:36:10

也许在您反编译的版本之前,您的类路径中存在该类的另一个版本。
编辑或者您已经更新了软件包,但忘记将其部署到运行时类路径,或者您尚未更新编译类路径,即您的运行时环境不同步与你的编译时环境。

public voidcompleteRow() 是在 2.0.5 中引入的。 您的运行时类路径中必须有 2.0.5 之前的版本。 如果您仍然遇到此问题,请研究进程启动的类路径。 如前所述,您正在使用 2.1.5 版本进行编译。

perhaps there is another version of this class in your classpath before the version that you decompiled.
edit: Or you have updated the package, but have forgotten to either deploy it to your runtime classpath or you havent updated the compile classpath, ie your runtime env is out of sync with your compiletime env.

public void completeRow() was introduced in 2.0.5. you must have a version before 2.0.5 in your runtime classpath. if you are still experiencing this problem, please study the classpath for the startup of the process. as stated before, you are compiling with the 2.1.5 version.

耳钉梦 2024-08-01 17:36:10

这对我有用。

我使用net beans IDE。 我只是删除了 httpclient 和 core jar 文件(我使用的是 4.2.1)并重新添加它们。 这似乎改变了顺序并且奏效了。

添加到“最后帕尔丁”的答案对我有帮助。

This worked for me.

I use net beans IDE. I simply deleted the httpclient and core jar files (I'm using 4.2.1) and re-added them. That seemed to change the order and it worked.

Adding to "Last Paldin's" Answer that helped me.

诗化ㄋ丶相逢 2024-08-01 17:36:10

有一个有点类似的问题,经过更深入的调查,发现我添加的第 3 方 jar 中的 Table 类方法与 itext-2.0.4 jar 的相应表方法冲突。 因此,我从类路径和库文件夹中删除了第 3 方 jar,并运行了干净的重建,现在它呈现完美。

Had a somewhat similar problem, on deeper investigation noticed that a Table class method in a 3rd party jar I had added was conflicting with itext-2.0.4 jar's corresponding table method. So I removed the 3rd party jar from the classpath and Libraries folder and run a clean rebuild and now it renders perfectly.

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