代码之家  ›  专栏  ›  技术社区  ›  Mercer

我的验证程序窗体出现空指针异常

  •  0
  • Mercer  · 技术社区  · 14 年前

    你好,我有一个类窗体,在这里我实现了这样的验证器

    public class LoginForm extends ActionForm {
        private String login;
        private String password;
        public void setLogin(String login) {
            this.login = login;
        }
        public string getLogin() {
            return login;
        }
        public void setPassword(String password) {
            this.password = password;
        }
        public string getPassword() {
            return password;
        }
        public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {
            ActionErrors errors = new ActionErrors();
            if ( login==null || login.lenght()<=8) {
                errors.add("error",new ActionMessage ("error.login"));
            }
            if ( password==null || password.lenght()<=8) {
                errors.add("error",new ActionMessage ("error.password"));
            }
            return errors;
        }
    }
    

    问题是这行中有nullpointerException

    errors.add("error",new ActionMessage ("error.login"));
    

    StackTrace:

    Etat HTTP 500 - 
    
    --------------------------------------------------------------------------------
    
    type Rapport d'exception
    
    message 
    
    description Le serveur a rencontré une erreur interne () qui l'a empèché de satisfaire la requête.
    
    exception 
    
    java.lang.NullPointerException
        at fr.xxxx.xxxxx.xxxxx.forms.LoginForm.validate(AdministrationSaisieTarifsForm.java:77)
        at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:950)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:207)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:199)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:145)
        at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
        at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
        at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
        at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
        at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
        at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
        at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
        at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
        at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)
        at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
        at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81)
        at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
        at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:217)
        at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
        at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:106)
        at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
        at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:229)
        at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
        at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
        at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:165)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:145)
        at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:196)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:165)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:145)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:139)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)
        at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2460)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
        at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:119)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)
        at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:157)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
        at java.lang.Thread.run(Thread.java:534)
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Manuel Selva    14 年前

    您提供的堆栈报告的异常不在您提到的类/行中,而是在下面的行中:

    Fr.XXXX.XXXXX .表格.管理SasieTeaFiSts.验证(管理SasieTeaFiSts.java:77)

    看看 AdministrationSaisieTarifsForm.validate(...) 根据您提供的堆栈,问题就在这里。

        2
  •  0
  •   Manuel Selva    14 年前

    我决定根据您对堆栈跟踪的更新打开另一个答案。

    下一行

    errors.add("error",new ActionMessage ("error.login"));
    

    仅当错误变量为空或在粘贴的代码中,此变量的初始化方式是:

    ActionErrors errors = new ActionErrors();
    

    因此,第77行不是您认为的行。不可能是这个。