zoukankan      html  css  js  c++  java
  • InvocationTargetException 异常

     

     

    • TTP ERROR 500

      Problem accessing /blog!add.do. Reason:

          java.lang.reflect.InvocationTargetException

       

      Caused by:

      org.blog.common.web.ObjectFactoryException: java.lang.reflect.InvocationTargetException
      	at org.blog.common.web.ControllerFactory.executeMethod(ControllerFactory.java:72)
      	at org.blog.common.web.ControllerFactory.control(ControllerFactory.java:23)
      	at org.blog.common.web.ControlServlet.process(ControlServlet.java:45)
      	at org.blog.common.web.ControlServlet.doGet(ControlServlet.java:25)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
      	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
      	at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
      	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
      	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
      	at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at org.mortbay.jetty.Server.handle(Server.java:326)
      	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
      	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
      	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
      	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
      	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
      Caused by: java.lang.reflect.InvocationTargetException
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
      	at org.blog.common.web.ControllerFactory.executeMethod(ControllerFactory.java:66)
      	... 30 more
      Caused by: java.lang.IllegalStateException: The current user is not logged in.
      	at com.google.appengine.api.users.UserServiceImpl.isUserAdmin(UserServiceImpl.java:96)
      	at org.blog.common.web.Controller.checkAdmin(Controller.java:92)
      	at org.blog.blog.web.BlogController.add(BlogController.java:23)
      	... 36 more
      

      Caused by:

      java.lang.reflect.InvocationTargetException
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
      	at org.blog.common.web.ControllerFactory.executeMethod(ControllerFactory.java:66)
      	at org.blog.common.web.ControllerFactory.control(ControllerFactory.java:23)
      	at org.blog.common.web.ControlServlet.process(ControlServlet.java:45)
      	at org.blog.common.web.ControlServlet.doGet(ControlServlet.java:25)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
      	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
      	at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
      	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
      	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
      	at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at org.mortbay.jetty.Server.handle(Server.java:326)
      	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
      	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
      	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
      	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
      	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
      Caused by: java.lang.IllegalStateException: The current user is not logged in.
      	at com.google.appengine.api.users.UserServiceImpl.isUserAdmin(UserServiceImpl.java:96)
      	at org.blog.common.web.Controller.checkAdmin(Controller.java:92)
      	at org.blog.blog.web.BlogController.add(BlogController.java:23)
      	... 36 more
      

      Caused by:

      java.lang.IllegalStateException: The current user is not logged in.
      	at com.google.appengine.api.users.UserServiceImpl.isUserAdmin(UserServiceImpl.java:96)
      	at org.blog.common.web.Controller.checkAdmin(Controller.java:92)
      	at org.blog.blog.web.BlogController.add(BlogController.java:23)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
      	at org.blog.common.web.ControllerFactory.executeMethod(ControllerFactory.java:66)
      	at org.blog.common.web.ControllerFactory.control(ControllerFactory.java:23)
      	at org.blog.common.web.ControlServlet.process(ControlServlet.java:45)
      	at org.blog.common.web.ControlServlet.doGet(ControlServlet.java:25)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
      	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
      	at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
      	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
      	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
      	at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at org.mortbay.jetty.Server.handle(Server.java:326)
      	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
      	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
      	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
      	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
      	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
      
      Powered by Jetty:// 
       
    • 戴威
      戴威 回答于 2011-01-05 21:02
       

       

      	/**
      	 * 执行方法
      	 * @param obj
      	 * @param methodName
      	 * @throws RequestNotFoundException
      	 * @throws ObjectFactoryException
      	 */
      	private static void executeMethod(Object obj, String methodName) throws 
      			RequestNotFoundException, ObjectFactoryException {
      		try {
      			Method method = obj.getClass().getMethod(methodName);
      			method.invoke(obj);
      		} catch(NoSuchMethodException e) {
      			throw new RequestNotFoundException(
      					"无法找到方法:" + methodName, e);
      		} catch(Exception e) {
      			e.printStackTrace();
      			throw new ObjectFactoryException(e);
      		}
      	}
      执行method.invoke(obj);这句时报错
       
       
    • 戴威
      戴威 回答于 2011-01-05 21:04
       

       

          /**
           * Invokes the underlying method represented by this <code>Method</code> 
           * object, on the specified object with the specified parameters.
           * Individual parameters are automatically unwrapped to match
           * primitive formal parameters, and both primitive and reference
           * parameters are subject to method invocation conversions as
           * necessary.
           *
           * <p>If the underlying method is static, then the specified <code>obj</code> 
           * argument is ignored. It may be null.
           *
           * <p>If the number of formal parameters required by the underlying method is
           * 0, the supplied <code>args</code> array may be of length 0 or null.
           *
           * <p>If the underlying method is an instance method, it is invoked
           * using dynamic method lookup as documented in The Java Language
           * Specification, Second Edition, section 15.12.4.4; in particular,
           * overriding based on the runtime type of the target object will occur.
           *
           * <p>If the underlying method is static, the class that declared
           * the method is initialized if it has not already been initialized.
           *
           * <p>If the method completes normally, the value it returns is
           * returned to the caller of invoke; if the value has a primitive
           * type, it is first appropriately wrapped in an object. However,
           * if the value has the type of an array of a primitive type, the
           * elements of the array are <i>not</i> wrapped in objects; in
           * other words, an array of primitive type is returned.  If the
           * underlying method return type is void, the invocation returns
           * null.
           *
           * @param obj  the object the underlying method is invoked from
           * @param args the arguments used for the method call
           * @return the result of dispatching the method represented by
           * this object on <code>obj</code> with parameters
           * <code>args</code>
           *
           * @exception IllegalAccessException    if this <code>Method</code> object
           *              enforces Java language access control and the underlying
           *              method is inaccessible.
           * @exception IllegalArgumentException  if the method is an
           *              instance method and the specified object argument
           *              is not an instance of the class or interface
           *              declaring the underlying method (or of a subclass
           *              or implementor thereof); if the number of actual
           *              and formal parameters differ; if an unwrapping
           *              conversion for primitive arguments fails; or if,
           *              after possible unwrapping, a parameter value
           *              cannot be converted to the corresponding formal
           *              parameter type by a method invocation conversion.
           * @exception InvocationTargetException if the underlying method
           *              throws an exception.
           * @exception NullPointerException      if the specified object is null
           *              and the method is an instance method.
           * @exception ExceptionInInitializerError if the initialization
           * provoked by this method fails.
           */
          public Object invoke(Object obj, Object... args)
      	throws IllegalAccessException, IllegalArgumentException,
                 InvocationTargetException
          {
              if (!override) {
                  if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
                      Class caller = Reflection.getCallerClass(1);
                      Class targetClass = ((obj == null || !Modifier.isProtected(modifiers))
                                           ? clazz
                                           : obj.getClass());
      
      		boolean cached;
      		synchronized (this) {
      		    cached = (securityCheckCache == caller)
      			    && (securityCheckTargetClassCache == targetClass);
      		}
      		if (!cached) {
      		    Reflection.ensureMemberAccess(caller, clazz, obj, modifiers);
      		    synchronized (this) {
      			securityCheckCache = caller;
      			securityCheckTargetClassCache = targetClass;
      		    }
      		}
                  }
              }
              if (methodAccessor == null) acquireMethodAccessor();
              return methodAccessor.invoke(obj, args);
          }

      最深只能追踪到这句 return methodAccessor.invoke(obj, args);报错

      在深入下去就是native的类了

       
       
    • 戴威
      戴威 回答于 2011-01-05 21:06
       

      平台是google app engine project

      这个是我写的一个对象工厂

       
       
    • 红薯
      红薯 回答于 2011-01-05 21:07
       

      请看 http://www.oschina.net/code/snippet_12_1 这个类的第 103 行

      捕捉到这个异常后要调用 .getCause() 方法才能获取真实的异常信息。

       
       
    • 戴威
      戴威 回答于 2011-01-05 21:13
       

      引用来自#5楼“红薯”的帖子

      请看 http://www.oschina.net/code/snippet_12_1 这个类的第 103 行

      捕捉到这个异常后要调用 .getCause() 方法才能获取真实的异常信息。

      感谢红薯老大,原来是实反射的那个方法报错了。

       
       
    • 戴威
      戴威 回答于 2011-01-05 21:15
       

       

      	/**
      	 * 执行方法
      	 * @param obj
      	 * @param methodName
      	 * @throws RequestNotFoundException
      	 * @throws ObjectFactoryException
      	 */
      	private static void executeMethod(Object obj, String methodName) throws 
      			RequestNotFoundException, ObjectFactoryException {
      		try {
      			Method method = obj.getClass().getMethod(methodName);
      			method.invoke(obj);
      		} catch(NoSuchMethodException e) {
      			throw new RequestNotFoundException(
      					"无法找到方法:" + methodName, e);
      		} catch(InvocationTargetException e) {
      			Throwable t = e.getCause();
      			t.printStackTrace();
      			throw new ObjectFactoryException(t);
      		} catch(Exception e) {
      			e.printStackTrace();
      			throw new ObjectFactoryException(e);
      		}
      	}
      改造之后的代码,再次感谢红薯老大的帮助
       
       
    • programtic
      programtic 回答于 2011-01-06 08:50
       

      百度已经收录了oschina的这个异常InvocationTargetException ,速度真快。

  • 相关阅读:
    使用IDEA打包出现“Cleaning up unclosed ZipFile for archive”错误
    Kafka读取本地文件作为生产者
    Redis连接池
    如果javaapi长时间消费不到数据
    Redis 持久化的两种方式
    kafka结合streaming的两种方式
    二分法查找
    shell脚本学习
    Md5Utils
    idea添加jar包
  • 原文地址:https://www.cnblogs.com/ningxu/p/3391965.html
Copyright © 2011-2022 走看看