gpt4 book ai didi

java - 在实现的方法上获取 java.lang.AbstractMethodError

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:24:31 25 4
gpt4 key购买 nike

如标题所述,我在我的类明确实现的方法上得到了 java.lang.AbstractMethodError。完整的错误信息是:

java.lang.AbstractMethodError: htmlexport.HTMLExport.getParameterFormDescriptor()Ljava/util/List;

我有一个定义方法如下的接口(interface):

List<ParamFormElement> getParameterFormDescriptor();

正如我所说,这个方法是由实现类实现的。

该接口(interface)包含在我本地 Maven 存储库中的一个 jar 中。我已经尝试了 mvn cleanmvn install 并修改了版本号,但这并没有解决问题。

实现类位于我使用 ANT 脚本创建的另一个 jar 文件中。然后通过主应用程序中的类加载器加载该文件。

我为什么会收到此错误的任何线索?接口(interface)定义的所有其他方法均有效。

代码来了

我有一个 Wicket WebPage,我可以在其中调用此方法:

public class AddJobPage extends BasePage {

public AddJobPage(final PageParameters params) {
super(params);

final Workable w =
WorkableManager.getInstance().findWorkableByName(params.get("workableName").toString());
w.getParameterFormDescriptor();
}

}

WorkableManager 使用 URLClassLoader 在内部加载包含实现类的 jar 文件。这工作正常,我得到一个实例需要的类。

定义方法的接口(interface)是:

public interface Workable {

List<ParamFormElement> getParameterFormDescriptor();

}

实现类如下所示(Module extends Workable):

public class HTMLExport implements Module {

@Override
public final List<ParamFormElement> getParameterFormDescriptor() {
final List<ParamFormElement> form = new ArrayList<>();
form.add(new ParamFormElement(ParamFormElement.Type.TEXT, "Bitte eingeben:", "test"));
return form;
}

}

该接口(interface)位于一个单独的项目中,并在我的本地 Maven 存储库中组装为一个 jar 文件。 HTMLExport 类也在不同的项目中,并且使用 Ant 编译和组装。生成的 jar 文件位于我的主应用程序旁边的文件夹中,正如我所说,加载类是有效的。主要应用是一个 Maven 项目,并将接口(interface)添加为依赖项。在 Eclipse 中,我没有任何错误或警告。

堆栈跟踪如下:

Root cause:

java.lang.AbstractMethodError: htmlexport.HTMLExport.getParameterFormDescriptor()Ljava/util/List;
at web.pages.AddJobPage.<init>(AddJobPage.java:30)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:171)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:99)
at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:137)
at org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:268)
at org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:166)
at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78)
at org.apache.wicket.request.handler.render.WebPageRenderer.isPageStateless(WebPageRenderer.java:300)
at org.apache.wicket.request.handler.render.WebPageRenderer.shouldRenderPageAndWriteResponse(WebPageRenderer.java:342)
at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:203)
at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:837)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:261)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:203)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:284)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1631)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:549)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:568)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1111)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:478)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1045)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:199)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:462)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:279)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:232)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:534)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
at java.lang.Thread.run(Thread.java:722)

Complete stack:

org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public web.pages.AddJobPage(org.apache.wicket.request.mapper.parameter.PageParameters)' and argument 'workableName=[HTML Export]'. An exception has been thrown during construction!
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:194)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:99)
at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:137)
at org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:268)
at org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:166)
at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78)
at org.apache.wicket.request.handler.render.WebPageRenderer.isPageStateless(WebPageRenderer.java:300)
at org.apache.wicket.request.handler.render.WebPageRenderer.shouldRenderPageAndWriteResponse(WebPageRenderer.java:342)
at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:203)
at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:837)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:261)

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:171)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:99)
at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:137)
at org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:268)
at org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:166)
at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78)
at org.apache.wicket.request.handler.render.WebPageRenderer.isPageStateless(WebPageRenderer.java:300)
at org.apache.wicket.request.handler.render.WebPageRenderer.shouldRenderPageAndWriteResponse(WebPageRenderer.java:342)
at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:203)
at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:837)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:261)

最佳答案

确保您的类路径中有最新的 jar 文件,而不是旧副本。如果您在运行时看到这种情况,这是由于不兼容的二进制文件造成的

来自 Oracle java 站点

Thrown when an application tries to call an abstract method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.

Link to Class AbstractMethodError

也可以尝试使用 -U 标志强制更新依赖项。

mvn clean install -U

关于java - 在实现的方法上获取 java.lang.AbstractMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23656915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com