This discussion is archived
5 Replies Latest reply: Mar 13, 2013 2:13 AM by gimbal2 RSS

does anybody tell me why null pointer excp.

995374 Newbie
Currently Being Moderated
package com.multistep.action;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import com.multistep.dao.ProfileDao;
import com.multistep.form.ProfileTO;









public class RegisterAction extends HttpServlet {

     /**
     *
     */
     private static final long serialVersionUID = 6029188081387087600L;

     /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
     public void doPost(HttpServletRequest request, HttpServletResponse response)
               throws ServletException, IOException {

          String target="LoginForm.jsp?status=Some problem occured during Registration,please login again..";
          try{
          ProfileTO rb = new ProfileTO();
          
     
               
               
               Map map=request.getParameterMap();
          try {
               BeanUtils.populate(rb, map);
          
               
               
     
     /*BeanUtils.copyProperties(rb1, rb);
          System.out.println(BeanUtils.cloneBean(rb).toString());
          System.out.println(BeanUtils.getDebug());
          System.out.println(BeanUtils.getIndexedProperty(map,"username"));*/
     
               
               
          } catch (IllegalAccessException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
          } catch (InvocationTargetException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
               
          }
boolean flag=new ProfileDao().registration(rb);
if(rb.getLogintype().equalsIgnoreCase("student"))
{
     if(flag)
target = "LoginForm.jsp?status=Registration Success";
else
target = "Registerform.jsp?status=Registration Failed";
}
else
{
     if(flag)
target = "Registerform.jsp?status=Registration Success";
else
target = "Registerform.jsp?status=Registration Failed";
}
     
          }
          catch(Exception e){e.printStackTrace();}
RequestDispatcher rd = request.getRequestDispatcher(target);
rd.forward(request,response);
     }

}


ERRORS:-null ptr. exp.
  • 1. Re: does anybody tell me why null pointer excp.
    Kayaman Guru
    Currently Being Moderated
    992371 wrote:
    ERRORS:-null ptr. exp.
    First of all, if you're posting code, put it between
     tags to format it nicely.
    
    Secondly, how do you expect "ERRORS:-null ptr. exp." to be helpful? Java gives you the stacktrace where it tells you the exact line where the NullPointerException happens, so go read that.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  • 2. Re: does anybody tell me why null pointer excp.
    995374 Newbie
    Currently Being Moderated
    at Line No. 76 Nullptr exp.
  • 3. Re: does anybody tell me why null pointer excp.
    EJP Guru
    Currently Being Moderated
    Post the stack trace. Post the entire stack trace. Cut and paste it. Do not abbreviate, do not guess, do not leave out vital information. And indicate which line of your code is the one where the exception is thrown from.

    Otherwise you are just wasting everybody's time.
  • 4. Re: does anybody tell me why null pointer excp.
    Kayaman Guru
    Currently Being Moderated
    992371 wrote:
    at Line No. 76 Nullptr exp.
    Well, there's your problem.
  • 5. Re: does anybody tell me why null pointer excp.
    gimbal2 Guru
    Currently Being Moderated
    Kayaman wrote:
    992371 wrote:
    at Line No. 76 Nullptr exp.
    Well, there's your problem.
    Yep. A variable you're using on that line contains a null-value. Now go figure out why. Usually it is simply forgetting to initialize it.

    NOTE: I wonder why this servlet question was asked in the JSP forum. The servlet forum is right next to it :/ Its like zero effort is put into this at all...

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points