抛出意外异常:java.lang.reflect.InvocationTargetException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4945057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:44:19  来源:igfitidea点击:

threw an unexpected exception: java.lang.reflect.InvocationTargetException

javahibernategwtjboss

提问by Ashfak Balooch

I am working on GWT-Hibernate application, my application works perfectly on integrated GWT environment and even on external server tomcat. I need to deploy my application on JBoss V 6.0. I am able to successfully deploy my application on JBoss and able to run until on point of execution. At particular button click application threw an unexpected exception: java.lang.reflect.InvocationTargetException

我正在开发 GWT-Hibernate 应用程序,我的应用程序在集成 GWT 环境甚至外部服务器 tomcat 上都能完美运行。我需要在 JBoss V 6.0 上部署我的应用程序。我能够在 JBoss 上成功部署我的应用程序,并且能够一直运行到执行点。在特定按钮单击应用程序抛出意外异常:java.lang.reflect.InvocationTargetException

Normally "java.lang.reflect.InvocationTargetException" occurs when java compiler finds 2 different classes with same name in 2 different packages. when you are importing both classes at a time and when you are trying to create object of that class it throws "java.lang.reflect.InvocationTargetException" exception.

通常“java.lang.reflect.InvocationTargetException”发生在 java 编译器在 2 个不同的包中发现 2 个具有相同名称的不同类时。当您一次导入两个类并且尝试创建该类的对象时,它会抛出“ java.lang.reflect.InvocationTargetException”异常。

Now I am not able to figure out where compiler is finds my two different class! Is there any method available so that I can know the exact location (i.e Physical path) where it finds the two different path, So that I can remove the bad one.

现在我无法弄清楚编译器在哪里找到我的两个不同的类!有什么方法可以让我知道它找到两条不同路径的确切位置(即物理路径),以便我可以删除坏的路径。

Any help would be appreciated.

任何帮助,将不胜感激。

Thanking You,

感谢您,

Regards,

问候,

EDIT :

编辑 :

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/myProj]] (http-127.0.0.1-8080-4) Exception while dispatching incoming RPC call: com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public com.proj.client.beans.domain.common.transaction.Document com.proj.server.actions.configuration.DocumentAction.saveDocument(com.proj.client.beans.domain.common.transaction.Document,java.lang.Long)' threw an unexpected exception: java.lang.reflect.InvocationTargetException
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:378) [:]
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:361) [:]
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:329) [:]
    at com.googlcode.strut2gwtplugin.interceptor.GWTServlet.processCall(GWTServlet.java:138) [:]
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:224) [:]
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62) [:]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [:1.0.0.Final]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
    at com.googlcode.strut2gwtplugin.interceptor.GWTInterceptor.intercept(GWTInterceptor.java:49) [:]
    at com.opensymphony.xwork2.DefaultActionInvocation.doProfiling(DefaultActionInvocation.java:224) [:]
    at com.opensymphony.xwork2.DefaultActionInvocation.doProfiling(DefaultActionInvocation.java:223) [:]
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) [:]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) [:]
    at com.proj.server.LoginInterceptor.intercept(LoginInterceptor.java:37) [:]
    at com.opensymphony.xwork2.DefaultActionInvocation.doProfiling(DefaultActionInvocation.java:224) [:]
    at com.opensymphony.xwork2.DefaultActionInvocation.doProfiling(DefaultActionInvocation.java:223) [:]
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) [:]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) [:]
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50) [:]
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504) [:]
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422) [:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final]
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
    at java.lang.Thread.run(Thread.java:662) [:1.6.0_23]
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_23]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_23]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_23]
    at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_23]
    at com.googlcode.strut2gwtplugin.interceptor.GWTServlet.processCall(GWTServlet.java:127) [:]
    ... 36 more
Caused by: java.lang.NullPointerException
    at com.proj.server.actions.configuration.DocumentAction.saveDocument(DocumentAction.java:161) [:]
    ... 41 more

采纳答案by Hardik Mishra

Try to deploy the code on jboss-5.0.0.GA

尝试将代码部署在 jboss-5.0.0.GA

Hope it helps

希望能帮助到你

回答by Joachim Sauer

InvocationTargetExceptiondoesn't in any way automatically imply two different classes with the same name in two different packages (in fact, I've got a hard time imagining how that situation could lead to that exception).

InvocationTargetException不会以任何方式自动暗示两个不同包中具有相同名称的两个不同类(实际上,我很难想象这种情况如何导致该异常)。

An InvocationTargetExceptionis simply the result when a method invoked through reflection throws an exception on its own.

AnInvocationTargetException只是通过反射调用的方法自身抛出异常时的结果。

Do you have access to the stack trace? It should print both the location of the reflection call (near the top) and the actual exception thrown by the invoked code (near the bottom).

您可以访问堆栈跟踪吗?它应该打印反射调用的位置(靠近顶部)和调用代码抛出的实际异常(靠近底部)。

回答by BobV

The last bit of the stack trace looks relevant here:

堆栈跟踪的最后一点在这里看起来很相关:

Caused by: java.lang.NullPointerException
at com.proj.server.actions.configuration.DocumentAction.saveDocument(DocumentAction.java:161)

The exception that you're describing usually manifests as an IncompatibleClassChangeErroror even more strangely as Foo.class != Foo.classwhen multiple ClassLoaders are involved.

您所描述的异常通常表现为一个IncompatibleClassChangeError或什至更奇怪的Foo.class != Foo.class是涉及多个 ClassLoader 时。

回答by Stephen C

As @Joachim's answer says, InvocationTargetExceptionis thrown when a method that is called using Method.invoke(...)throws a checked exception. The actual exception is wrapped in an InvocationTargetExceptionwhich is then thrown.

正如@Joachim 的回答所说,InvocationTargetException当调用 using 的方法Method.invoke(...)抛出已检查异常时抛出。实际的异常被包装在InvocationTargetException然后被抛出的an中。

In this particular case, the stacktrace tells us that original exception was a NullPointerExceptionthrown at "DocumentAction.java:161". Track down and fix the cause of that exception.

在这种特殊情况下,堆栈跟踪告诉我们原始异常是NullPointerException在“DocumentAction.java:161”处抛出的。追踪并修复该异常的原因。



I don't see any evidence that this has anything to do with different versions of some class. I'd treat it as a normal NPE to start with, and try to figure where the nullis coming from.

我没有看到任何证据表明这与某些类的不同版本有关。我会把它当作一个正常的 NPE 开始,并尝试弄清楚null它来自哪里。