Announcement Announcement Module
Collapse
No announcement yet.
Npe Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Npe

    Hi,
    I am getting this wierd exception.. I am not able to find where the problem could be. I am trying to route to a controller by URL Mapping.

    Code:
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object arg2, BindException arg3) throws Exception {
    		// TODO Auto-generated method stub
    		
    		HttpSession session =request.getSession(true);
    	    Enumeration name=request.getParameterNames();
    	    MetaData md=new MetaData();
    	    System.out.println("Save or update1");
    	    classname=(String)session.getAttribute("classname");
    	 	
    	    String[] commands=classname.split("[.]");
    		
    		 valList=dd.getFields((String)session.getAttribute("objectType"));
    	    
    		
    		//pkfield=md.get_PrimaryKeyField(commands[commands.length-1]);
    		pkfield=md.getPK(valList);
    		map_dump=new HashMap();
    	    updatedList=new ArrayList();
    	    doneList.clear();
    	    updatedList.clear();
    	    map_dump.clear();
            String paramList="";
            System.out.println("Save or update1");
            while(name.hasMoreElements())
             {
              String paramName = (String) name.nextElement();
              String paramValue= (String) request.getParameter(paramName);
              if(!paramName.equals("Submit") && !paramName.equals("objectType") && !paramName.equals("NoO") && !paramName.equals("classname"))
              {
    			  paramList=paramList+paramName+"="+paramValue+"   ;  ";
    			  String s[]=paramName.split("_");
    			  String paramn=paramName.substring(0,paramName.length()-s[s.length-1].length()-1);
    			  String datatype= md.getFieldType(valList, paramn);
    			  Object obj=md.return_value(datatype,paramValue);
    			  map_dump.put(paramName, obj);
    	       }
             }	
            System.out.println("Save or update12");
           
    			create_updateList();
    			System.out.println("Entities to be persisted: "+updatedList.size());
    			Iterator i=updatedList.listIterator();
    	         while(i.hasNext())
    	         {
    	        	 System.out.println();
    	        	 Object obj=i.next();
    	        	 Class c=obj.getClass();
    	        	 Method[] methods=c.getDeclaredMethods();
    	        	 for(int a=0;a<methods.length;a++)
    	        	 {
    	        		 Method m=methods[a];
    	        		 String name1 = m.getName();
    	        	      try {
    	        	    	  if(name1.startsWith("get"))
    	        	    	  { 
    	        	    		  String fieldname=name1.substring(3);
    	        	    		  Object ret_str =(Object) m.invoke(obj,nullargs);
    	        	    		  System.out.print("  "+ret_str);
    	        	    	  }
    					} catch (IllegalArgumentException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					} catch (IllegalAccessException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					} catch (InvocationTargetException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					} 
    					
    	        	 }// end of for
    	         }// end of while
    	         
    	         AmendEntityController aec=new AmendEntityController();
    	         aec.performAction1(updatedList);
    	         updatedList.clear();
    	         SearchEntityController sec=new SearchEntityController();
    	         Table tab=new Table(commands[commands.length-1], new HashMap());
    	         List l1= sec.performAction1(tab);
    	         session.setAttribute("datalist", l1);
    		return new ModelAndView(getSuccessView());
    	}
    Exception:
    Code:
    exception 
    
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:406)
    	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:358)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    
    
    root cause 
    
    java.lang.NullPointerException
    	springexample.contoller.AmendEntityController.onSubmit(Unknown Source)
    	org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:258)
    	org.springframework.web.servlet.mvc.AbstractFormController.handleInvalidSubmit(AbstractFormController.java:649)
    	org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:256)
    	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:723)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)
    	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:358)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    I am using JBoss as my app-server. This is what I see on the JBoss console
    Code:
    17:27:11,118 ERROR [Engine] StandardWrapperValve[sampleBankingServlet]: Servlet.service() for servlet sampleBankingServlet threw exception
    java.lang.NullPointerException
    	at springexample.contoller.AmendEntityController.onSubmit(Unknown Source)
    	at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:258)
    	at org.springframework.web.servlet.mvc.AbstractFormController.handleInvalidSubmit(AbstractFormController.java:649)
    	at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:256)
    	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:723)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:358)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:72)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
    	at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:275)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
    	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
    	at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
    	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
    	at java.lang.Thread.run(Thread.java:595)
    I would glad if anybody could point me to the error. I have been trying to debug this for over 5 hrs

  • #2
    Well apparently something is not being set. Hence the NullPointer, I see no linenumbers, zo try to recompile with debug info.

    But I guess that the following lines are the problem, if there is no session then the classname attribute will not be set. And hence return null, calling split on a null object well causes trouble.

    Also never keep state in a Controller by using member variables. Controllers are per applicationcontext singletons.

    Code:
    classname=(String)session.getAttribute("classname");	 	
    String[] commands=classname.split("[.]");
    You might try replacing the lines with the following (Using Spring 2.0). This will throw an error if the parameter is not present.

    Code:
    String classname= WebUtils.getRequiredSessionAttribute(request, "classname");

    Comment


    • #3
      npe

      hey thanks a lot!
      Like you said, these values were null.. there was a problem with my session variable.
      Thanks a lot once again..

      I really appreciate the help..

      Comment

      Working...
      X