nobita2811
New Member
I am getting a java.lang.NullPointerException:I have the getters and setters set for the validateUserNameManager.I am using xml based configurations and not using @Autowire.Its clear when processing reaches validateUserNameManager it gets the NP Exception i am not sure if my configurations and wiring are accurate. \[code\]if (validateUserNameManager.DoesUserNameExist(officer.getUserName()) == true){ errors.rejectValue("userName", "userName.exist"); }\[/code\]OfficerRegistrationValidation.java\[code\]public class OfficerRegistrationValidation implements Validator{ private final Logger logger = Logger.getLogger(getClass()); private ValidateUserNameManager validateUserNameManager; public boolean supports(Class<?> clazz) { return Officers.class.equals(clazz); } public void validate(Object target, Errors errors) { Officers officer = (Officers) target; if (officer.getUserName() == null){ errors.rejectValue("userName", "userName.required"); }else{ String userName = officer.getUserName(); logger.info("OfficerRegistrationValidation - UserName is not null so going to check if its valid for :" + userName); try { logger.info("OfficerRegistrationValidation - Just before try.....catch block...userName is :" + userName); logger.info("OfficerRegistrationValidation - about to evaluate if (validateUserNameManager.DoesUserNameExist(officer.getUserName()) == true)" ); if (validateUserNameManager.DoesUserNameExist(officer.getUserName()) == true){ errors.rejectValue("userName", "userName.exist"); } } catch (Exception e) { logger.info("OfficerRegistrationValidation - Error Occured When validating UserName"); logger.error("Message", e); errors.rejectValue("userName", "userName.error"); } }/** * @return the validateUserNameManager */ public ValidateUserNameManager getValidateUserNameManager() { logger.info("Getting - ValidateUserNameManager"); return validateUserNameManager; } /** * @param validateUserNameManager the validateUserNameManager to set */ public void setValidateUserNameManager( ValidateUserNameManager validateUserNameManager) { logger.info("Setting - ValidateUserNameManager"); this.validateUserNameManager = validateUserNameManager; } }\[/code\]ApplicationContext.xml\[code\]<bean id="officerRegistrationValidation" class="com.crimetrack.service.OfficerRegistrationValidation"> <property name="validateUserNameManager" ref="validateUserNameManager"/></bean><bean id="validateUserNameManager" class="com.crimetrack.service.ValidateUserNameManager"> <property name="officerDao" ref="officerDao"/></bean><bean id="officerDao" class="com.crimetrack.jdbc.JdbcOfficersDAO" > <property name="dataSource" ref="dataSource" /></bean>\[/code\] Servlet.xml\[code\] <bean name="/officer_registration.htm" class="com.crimetrack.web.OfficerRegistrationController"> <property name="divisionManager" ref="divisionManager" /> <property name="positionManager" ref="positionManager" /> <property name="genderManager" ref="genderManager"/> </bean><!-- __________________________________________________________________________________________________ --> <bean name="/validateUserName.htm" class="com.crimetrack.web.OfficerRegistrationController"> <property name="validateUserNameManager" ref="validateUserNameManager"/> </bean> <!-- __________________________________________________________________________________________________ --> \[/code\]StackTrace:\[code\]47840 [http-8084-1] DEBUG org.springframework.beans.TypeConverterDelegate - Converting String to [class java.lang.String] using property editor [org.springframework.beans.propertyeditors.StringTrimmerEditor@7079b2]47840 [http-8084-1] INFO com.crimetrack.service.OfficerRegistrationValidation - OfficerRegistrationValidation - UserName is not null so going to check if its valid for :adminzz47840 [http-8084-1] INFO com.crimetrack.service.OfficerRegistrationValidation - OfficerRegistrationValidation - Just before try.....catch block...userName is :adminzz47840 [http-8084-1] INFO com.crimetrack.service.OfficerRegistrationValidation - OfficerRegistrationValidation - about to evaluate if (validateUserNameManager.DoesUserNameExist(officer.getUserName()) == true)47840 [http-8084-1] INFO com.crimetrack.service.OfficerRegistrationValidation - OfficerRegistrationValidation - Error Occured When validating UserName47840 [http-8084-1] ERROR com.crimetrack.service.OfficerRegistrationValidation - Messagejava.lang.NullPointerException at com.crimetrack.service.OfficerRegistrationValidation.validate(OfficerRegistrationValidation.java:51) at org.springframework.validation.DataBinder.validate(DataBinder.java:725) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:815) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:367) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source)\[/code\]