static WebAppAccess webAppAccess;
static
{
String userId = webAppAccess.getVariables().getString(
"moduleSelect_var");
if(userId.equals("set"))
对于上面的代码我正在设置像这样的错误
The error message returned was: "Error in method main. java.lang.ExceptionInInitializerError".
请参阅已部署的应用程序中的logs文件夹以获取其他错误信息。
单击此处隐藏详细的错误消息。
Exception Error in method main. java.lang.ExceptionInInitializerError
Stack Trace
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java(Compiled Code))
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java(Compiled Code))
at java.lang.reflect.Constructor.newInstance(Constructor.java(Compiled Code))
at java.lang.Class.newInstance3(Class.java(Compiled Code))
at java.lang.Class.newInstance(Class.java(Compiled Code))
at com.bowstreet.webapp.structures.VariableUtil.instantiateObjectValue(VariableUtil.java:203)
at com.bowstreet.webapp.structures.RuntimeVariableImpl.getVariableValue(RuntimeVariableImpl.java:371)
at com.bowstreet.webapp.structures.RuntimeVariableImpl.getValue(RuntimeVariableImpl.java:126)
at com.bowstreet.webapp.structures.VariablesImpl.getVariableValue(VariablesImpl.java:584)
at com.bowstreet.webapp.structures.VariablesImpl.getObject(VariablesImpl.java:388)
at com.bowstreet.webapp.engine.actions.MethodAction.getMethodClassInstance(MethodAction.java:163)
at com.bowstreet.webapp.engine.actions.MethodAction.callAction(MethodAction.java:86)
at com.bowstreet.webapp.engine.WebAppAccessImpl.callMethod(WebAppAccessImpl.java:405)
at genjava._qwe.main(_qwe.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code))
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code))
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at com.bowstreet.webapp.engine.actions.MethodAction.callAction(MethodAction.java:90)
at com.bowstreet.webapp.engine.WebAppAccessImpl.callMethod(WebAppAccessImpl.java:405)
at com.bowstreet.webapp.engine.WebAppAccessImpl.processAction(WebAppAccessImpl.java:1046)
at com.bowstreet.webapp.engine.WebAppAccessImpl.processAction(WebAppAccessImpl.java:1146)
at com.bowstreet.webapp.engine.WebAppRequestRunner.doRequest(WebAppRequestRunner.java:364)
at com.bowstreet.webapp.engine.WebAppRunner.doActualRequest(WebAppRunner.java:866)
at com.bowstreet.webapp.engine.WebAppRunner.doRequest(WebAppRunner.java:526)
at com.bowstreet.webapp.engine.WebAppRunner.doRequest(WebAppRunner.java:291)
at com.bowstreet.webapp.engine.WebAppRunner.doRequest(WebAppRunner.java:228)
at com.bowstreet.webapp.engine.WebAppServlet.doPost(WebAppServlet.java:73)
at com.bowstreet.webapp.engine.WebAppServlet.doGet(WebAppServlet.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.geronimo.tomcat.valve.DefaultSubjectValve.invoke(DefaultSubjectValve.java:56)
at org.apache.geronimo.tomcat.GeronimoStandardContext$SystemMethodValve.invoke(GeronimoStandardContext.java:342)
at org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve.invoke(GeronimoBeforeAfterValve.java:31)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:392)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:869)
at java.lang.Thread.run(Thread.java:570)
Caused by: java.lang.NullPointerException
at com.grpf.OuterClass.(OuterClass.java:28)
... 52 more
答案 0 :(得分:0)
当webAppAccess
上的某个方法仍然为空时,你会调用一个方法,你得到一个NullPointerException
:
static WebAppAccess webAppAccess;
static
{
String userId = webAppAccess.getVariables().getString("moduleSelect_var");
// ^ here it is still null
if(userId.equals("set"))
首先为其分配一个对象来解决它:
static WebAppAccess webAppAccess;
static
{
webAppAccess = new WebAppAccess(); // or whatever the constructor is...
String userId = webAppAccess.getVariables().getString("moduleSelect_var");
if(userId.equals("set"))