Results 1 to 8 of 8
  1. #1
    priya diwan is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default how to remove null pointer exception in this page ?

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@page import="connectDatabase.GetConnection"%>
    <%@page import="java.sql.ResultSet"%>


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>

    </head>
    <body>


    <script type="text/javascript">
    function test () {
    var frm1 = document.getElementById("f1");
    var frm2 = document.getElementById("f2");
    }
    </script>



    <form id = "f1" onsubmit="return test()">
    <table border=7 align="center" >
    <tr>
    <td>
    <br>Location: <input type = text name = "loc"><br /><br />
    <%
    GetConnection obj = new GetConnection();
    ResultSet rs = obj.getTerminal();
    %>
    Terminal : <select name="lterminal">
    <%
    while (rs.next()) {
    %>
    <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>
    <%
    }
    %>
    </select>
    <br />
    <button type="reset" value="Reset">Clear</button>
    <button type="submit" value="search">Search </button>
    </td>
    </tr>
    </table>
    </form>

    <form id = "f2">
    Location Data<br>
    <%
    ResultSet rst = obj.getLocation();
    %>
    <table border=7 align="center">
    <tr>
    <th>Location Id</th>
    <th>Location Name</th>
    <th>Terminal</th>
    </tr>
    <%
    while (rst.next()) {
    %>
    <tr>
    <td><%=rst.getString(1)%></td>
    <td><%=rst.getString(2)%></td>
    <td><%=rst.getString(3)%></td>
    </tr>
    <%
    }
    %>

    </table>
    </form>

    </body>
    </html>

  2. #2
    priya diwan is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default Re: how to remove null pointer exception in this page ?

    this is the message shown while running the page----

    HTTP Status 500 -

    --------------------------------------------------------------------------------

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: An exception occurred processing JSP page /LocationSearch.jsp at line 37

    34: %>
    35: Terminal : <select name="lterminal">
    36: <%
    37: while (rs.next()) {
    38: %>
    39: <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>
    40: <%


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:524)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:435)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)


    root cause

    java.lang.NullPointerException
    org.apache.jsp.LocationSearch_jsp._jspService(Loca tionSearch_jsp.java:91)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:393)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)


    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.


    --------------------------------------------------------------------------------

    Apache Tomcat/6.0.14

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: how to remove null pointer exception in this page ?

    Please go through Guide For New Members and BB Code List - Java Programming Forum and edit your posts accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: how to remove null pointer exception in this page ?

    Ensure that 'rs' is not null.
    Why it is null I don't know as I don't generally try and read unformatted code.

    I will say that that database code should not be in a JSP page.
    That should be called from a servlet, normally in a data access layer, and the results (when turned into a model) will be sent to the JSP for display.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    sibernewf is offline Member
    Join Date
    Mar 2011
    Posts
    48
    Rep Power
    0

    Default Re: how to remove null pointer exception in this page ?

    I agree with Tolls. Run a debug and put a breakpoint at the obj = new GetConnection(); method.
    See what obj is once the GetConnection method has completed.

  6. #6
    techiepro is offline Member
    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    Default Re: how to remove null pointer exception in this page ?

    rs is null for sure. Post the GetConnection class here.

  7. #7
    Ramesh4800 is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: how to remove null pointer exception in this page ?

    this is not an issue.u have to ensure that every parameter should be initialized before u use it.this is simple u can try in Eclipse IDE.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: how to remove null pointer exception in this page ?

    First off, this is several months old.
    Second, what on earth are you talking about? The result set is null. This has nothing to do with parameters and everything to do with how they are creating the variable in their JSP page.

    And please don't use text speak...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Getting a null pointer exception when loading my JSP result page
    By rc1138 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-13-2011, 02:23 PM
  2. Null pointer exception a
    By TaxpayersMoney in forum New To Java
    Replies: 5
    Last Post: 08-16-2011, 12:37 AM
  3. Null pointer exception?
    By coffee in forum New To Java
    Replies: 4
    Last Post: 08-03-2009, 03:22 AM
  4. Null pointer exception
    By talha06 in forum JDBC
    Replies: 5
    Last Post: 07-14-2009, 01:12 AM
  5. Help with null pointer exception
    By gammaman in forum New To Java
    Replies: 4
    Last Post: 07-14-2009, 12:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •