Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: java.lang.NullPointerException

  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java.lang.NullPointerException

    Dear forum members,

    I try to use back my old doPost codes which used to work fine but now giving me NullPointerException.

    Hope someone can tell me what's going on.


     
    public class ProcessRegistration extends HttpServlet {
     
     
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
     
            Connection con = null;
            ResultSet rs = null;
            PreparedStatement ps = null;
            Statement stmt = null;
     try {
     
     
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                con = DriverManager.getConnection("jdbc:odbc:ABCODBC2");
     
      strCheck = "SELECT COUNT(*) FROM members WHERE strEmail=?";

    Really can't figure out what went wrong...


    And here's the error message:

    java.lang.NullPointerException
    at ProcessRegistration.doPost(ProcessRegistration.jav a:58)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:454)
    at java.lang.Thread.run(Thread.java:619)
    Last edited by tangara; August 3rd, 2013 at 09:46 PM. Reason: to add more details

  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: java.lang.NullPointerException

    Add some printlns to determine which variable has a null value, (somewhere around line 58 it seems?) then start backtracking to see why a value was not assigned.

  3. #3
    Member
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.NullPointerException

    At line58, my line is:

    String strName = request.getParameter("Fullname").trim();

    And I've put a printlns :
    out.println(strName);

    at the DoPost servlet there but it is not giving me any indication what go wrong. And the localhost just keep running and running without anything happen...like hang. Why is this so?

    Please help.

  4. #4
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: java.lang.NullPointerException

    Hello.
    You said you are getting Null Pointer Exception first.
    Then you say localhost keeps running.
    Its unclear.
    Please just state the exact problem you are getting.

    Syed.

  5. #5
    Member
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.NullPointerException

    Quote Originally Posted by syedbhai View Post
    Hello.
    You said you are getting Null Pointer Exception first.
    Then you say localhost keeps running.
    Its unclear.
    Please just state the exact problem you are getting.

    Syed.
    Sorry to have confused you but I just tested and tested.
    My latest test shows the same Null PointerException.

    Please advise how to stop the exception. Thank you.

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: java.lang.NullPointerException

    Quote Originally Posted by tangara View Post
    At line58, my line is:

    String strName = request.getParameter("Fullname").trim();

    And I've put a printlns :
    out.println(strName);
    Since that line is the declaration of strName, I would assume you put the println after that line..? Then I would assume nothing is printed because the NPE happens before the println..? What about request? Did you check to see if request is null?

  7. #7
    Member
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.NullPointerException

    Hi Jps,

    Yap. I have put the println not immediately after that line but somewhere at the part where I generate a message "Successful registration".

    At the Tomcat HTTP server monitor, I see that the request Method is Get. How come is Get when it's supposed to be POST.
    And the HTTP exit status (as set by servlet) Could not be determined.

    My onscreen browser is totally blank.

  8. #8
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: java.lang.NullPointerException

    Hello.
    Can you check if you are supplying the parameter "Fullname"? If this parameter is not available then you are invoking trim() on NULL.
    This could be the reason for NullPointerException.

    Syed.

  9. #9
    Member
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.NullPointerException

    Quote Originally Posted by syedbhai View Post
    Hello.
    Can you check if you are supplying the parameter "Fullname"? If this parameter is not available then you are invoking trim() on NULL.
    This could be the reason for NullPointerException.

    Syed.
    Hi Syedbhai,

    <code>

    <tr>
    <td>Full Name</td>
    <td><input type="text" id="FullName" name="FullName"></td>
    </tr>

    </code>

    I've change my form parameter to Fullname but now I'm getting a bigger error. The form can't be submitted and so I did a servlet debug.

    And the error message as follows (the thing is that Netbeans seems to be reading my past programmes and I'm not sure how to make Netbean terminate the reading from the past memory).

    Not sure if I have to repost the thread but here's the error from the Debugger console so that I do not have to re-post my codes.

    <code>

    Attaching to tomcat_shared_memory_id
    Not able to submit breakpoint LineBreakpoint FlowerService.java : 14, reason: The breakpoint is set outside of any class.
    Invalid LineBreakpoint FlowerService.java : 14
    LineBreakpoint URLClassLoader.java : 200 successfully submitted.
    User program running
    Breakpoint hit at line 200 in class java.net.URLClassLoader$1 by thread http-8084-10.
    Thread http-8084-10 stopped at URLClassLoader.java:200.
    </code>

    Tomcat 6.0.20 log shows blank.

    I'm totally stump. (

  10. #10
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: java.lang.NullPointerException

    Hello.
    I think the parameter names are case-sensitive. I am not sure. Just double-check it.
    You are reading "Fullname" in your servlet. But in your form its "FullName".
    The cases do not match.
    Just try to make it "Fullname" on the form as well.

    If you experience problems with netbeans/tomcat just shutdown and restart both netbeans and tomcat.
    Let me know.

    Syed.

  11. #11
    Member
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.NullPointerException

    Quote Originally Posted by syedbhai View Post
    Hello.
    I think the parameter names are case-sensitive. I am not sure. Just double-check it.
    You are reading "Fullname" in your servlet. But in your form its "FullName".
    The cases do not match.
    Just try to make it "Fullname" on the form as well.

    If you experience problems with netbeans/tomcat just shutdown and restart both netbeans and tomcat.
    Let me know.

    Syed.
    Hi Syed,

    I have followed your instruction to change to the form to match the beans. But, it's still not working. (

    Tomcat is still reading the memory thing.

    Can you teach me how to restart tomcat inside Netbean for I have been re-start Netbeans for more then 30 times I guess.

    Thanks and I hope to hear from you soon.

  12. #12
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: java.lang.NullPointerException

    Hello.
    Can you check your HTML code? Check the <form> tag.
    And see what HTTP method you are using - GET or POST. For this see if there is an attribute named "method" in the form tag.
    If you don't see "method" attribute in the form tag then add it and give the value "POST".

    Syed.

  13. #13
    Member
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.NullPointerException

    Quote Originally Posted by syedbhai View Post
    Hello.
    Can you check your HTML code? Check the <form> tag.
    And see what HTTP method you are using - GET or POST. For this see if there is an attribute named "method" in the form tag.
    If you don't see "method" attribute in the form tag then add it and give the value "POST".

    Syed.
    Here's what I have put:

    <form id="frmData" name="frmData" action="ProcessRegistration" method="post" >

    But, the problem is still there. (

    How do I restart Tomcat inside Netbean?

  14. #14
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: java.lang.NullPointerException

    Hello.
    Just reboot your computer.
    Compile your entire project.
    Star the tomcat server.
    Deploy the war file.
    And let us know.

    Syed.

  15. #15
    Member
    Join Date
    Jul 2011
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.NullPointerException

    Quote Originally Posted by syedbhai View Post
    Hello.
    Just reboot your computer.
    Compile your entire project.
    Star the tomcat server.
    Deploy the war file.
    And let us know.

    Syed.
    But, I already mentioned I have done the above for countless times......more than 100 or more times....(
    And I'm still awaiting how to restart tomcat server inside Netbean....What I notice though that it seems that tomcat server would re-start everytime...just don't know how to clear those memory thing....hope that you know how...

Similar Threads

  1. java.lang.NullPointerException
    By nikomania in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 12th, 2013, 04:16 PM
  2. [SOLVED] java.lang.NullPointerException
    By macko in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 3rd, 2011, 10:39 AM
  3. java.lang.NullPointerException
    By mwr76 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 8th, 2011, 04:39 PM
  4. java.lang.nullPointerException
    By ridg18 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 25th, 2010, 02:52 PM
  5. java.lang.NullPointerException - Help
    By mds1256 in forum Exceptions
    Replies: 5
    Last Post: November 30th, 2009, 05:31 PM