我是靠谱客的博主 成就板凳,最近开发中收集的这篇文章主要介绍ofbiz调用服务时报错:Service [xxxService] ran into an unexpected null object (null),觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
刚接触ofbiz框架不久,在开发helloworld的时候,遇到的问题,报错如下:
---- exception report ----------------------------------------------------------
[java] Service [showUsers] threw an unexpected exception/error
[java] Exception: org.ofbiz.service.GenericServiceException
[java] Message: Service [showUsers] ran into an unexpected null object (null)
[java] ---- cause ---------------------------------------------------------------------
[java] Exception: java.lang.NullPointerException
[java] Message: null
[java] ---- stack trace ---------------------------------------------------------------
[java] java.lang.NullPointerException
[java] sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[java] sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[java] java.lang.reflect.Method.invoke(Unknown Source)
[java] org.ofbiz.service.engine.StandardJavaEngine.serviceInvoker(StandardJavaEngine.java:96)
[java] org.ofbiz.service.engine.StandardJavaEngine.runSync(StandardJavaEngine.java:54)
[java] org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:390)
[java] org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:219)
[java] org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:159)
[java] com.diyagea.event.UserEvent.show(UserEvent.java:26)
[java] sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[java] sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[java] java.lang.reflect.Method.invoke(Unknown Source)
[java] org.ofbiz.webapp.event.JavaEventHandler.invoke(JavaEventHandler.java:92)
[java] org.ofbiz.webapp.event.JavaEventHandler.invoke(JavaEventHandler.java:78)
[java] org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:598)
[java] org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:367)
[java] org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:202)
[java] javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
[java] javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
[java] org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
[java] org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[java] org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:259)
[java] org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
[java] org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[java] org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
[java] org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
[java] org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
[java] org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
[java] org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
[java] org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
[java] org.ofbiz.catalina.container.CrossSubdomainSessionValve.invoke(CrossSubdomainSessionValve.java:62)
[java] org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
[java] org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
[java] org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
[java] org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
[java] java.lang.Thread.run(Unknown Source)
[java] --------------------------------------------------------------------------------
[java] 2015-12-02 14:02:28,475 (http-0.0.0.0-8443-2) [ TransactionUtil.java:285:ERROR]
[java] ---- exception report ----------------------------------------------------------
[java] [TransactionUtil.rollback]
[java] Exception: java.lang.Exception
[java] Message: Stack Trace
[java] ---- stack trace ---------------------------------------------------------------
[java] java.lang.Exception: Stack Trace
[java] org.ofbiz.entity.transaction.TransactionUtil.rollback(TransactionUtil.java:284)
[java] org.ofbiz.entity.transaction.TransactionUtil.rollback(TransactionUtil.java:266)
[java] org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:509)
[java] org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:219)
[java] org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:159)
[java] com.diyagea.event.UserEvent.show(UserEvent.java:26)
[java] sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[java] sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[java] java.lang.reflect.Method.invoke(Unknown Source)
[java] org.ofbiz.webapp.event.JavaEventHandler.invoke(JavaEventHandler.java:92)
[java] org.ofbiz.webapp.event.JavaEventHandler.invoke(JavaEventHandler.java:78)
[java] org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:598)
[java] org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:367)
[java] org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:202)
[java] javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
[java] javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
[java] org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
[java] org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[java] org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:259)
[java] org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
[java] org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[java] org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
[java] org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
[java] org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
[java] org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
[java] org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
[java] org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
[java] org.ofbiz.catalina.container.CrossSubdomainSessionValve.invoke(CrossSubdomainSessionValve.java:62)
[java] org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
[java] org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
[java] org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
[java] org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
[java] java.lang.Thread.run(Unknown Source)
[java] --------------------------------------------------------------------------------
[java] 2015-12-02 14:02:28,476 (http-0.0.0.0-8443-2) [ TransactionUtil.java:295:INFO ] [TransactionUtil.rollback] transaction rolled back
[java] 2015-12-02 14:02:28,476 (http-0.0.0.0-8443-2) [ TransactionUtil.java:219:WARN ] [TransactionUtil.commit] Not committing transaction, status is No Transaction (6)
[java] 2015-12-02 14:02:28,530 (http-0.0.0.0-8443-2) [ RequestHandler.java:599:INFO ] Ran Event [java:com.diyagea.event.UserEvent#show] from [request], result is [error]
[java] 2015-12-02 14:02:28,534 (http-0.0.0.0-8443-2) [ RequestHandler.java:414:WARN ] Could not find response in request [show] for event return [error]
[java] 2015-12-02 14:02:28,534 (http-0.0.0.0-8443-2) [ RequestHandler.java:703:INFO ] Rendering View [show], sessionId=4C8C296E242100020C212A889598E951.jvm1
[java] org.ofbiz.service.GenericServiceException: Service [showUsers] ran into an unexpected null object (null)
[java] at org.ofbiz.service.engine.StandardJavaEngine.serviceInvoker(StandardJavaEngine.java:110)
[java] at org.ofbiz.service.engine.StandardJavaEngine.runSync(StandardJavaEngine.java:54)
[java] at org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:390)
[java] at org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:219)
[java] at org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:159)
[java] at com.diyagea.event.UserEvent.show(UserEvent.java:26)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[java] at java.lang.reflect.Method.invoke(Unknown Source)
[java] at org.ofbiz.webapp.event.JavaEventHandler.invoke(JavaEventHandler.java:92)
[java] at org.ofbiz.webapp.event.JavaEventHandler.invoke(JavaEventHandler.java:78)
[java] at org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:598)
[java] at org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:367)
[java] at org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:202)
[java] at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
[java] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
[java] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
[java] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[java] at org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:259)
[java] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
[java] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[java] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
[java] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
[java] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
[java] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
[java] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
[java] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
[java] at org.ofbiz.catalina.container.CrossSubdomainSessionValve.invoke(CrossSubdomainSessionValve.java:62)
[java] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
[java] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
[java] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
[java] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
[java] at java.lang.Thread.run(Unknown Source)
[java] Caused by: java.lang.NullPointerException
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[java] at java.lang.reflect.Method.invoke(Unknown Source)
[java] at org.ofbiz.service.engine.StandardJavaEngine.serviceInvoker(StandardJavaEngine.java:96)
[java] ... 33 more
错误原因:service或event类中方法不是静态的,加上static即可
经过读ofbiz源码,发现ofbiz内部机制是通过调用类名直接调用配置好的service和event类中的静态方法
如果service或event中的方法不加static就会出现上述错误
而Struts和spring框架会把配置好的action和bean初始化好到一个容器中,所以不需要用static
最后
以上就是成就板凳为你收集整理的ofbiz调用服务时报错:Service [xxxService] ran into an unexpected null object (null)的全部内容,希望文章能够帮你解决ofbiz调用服务时报错:Service [xxxService] ran into an unexpected null object (null)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复