Results 1 to 2 of 2
  1. #1
    rc1138 is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Default Getting a null pointer exception when loading my JSP result page

    Hi all,

    I am working on an EJB application which contains some JSP pages.

    This is the index page

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Metric to Imperial Converter</title>
    </head>
    <body>
    <h1>Meter to Yard Converter</h1>
    <form action="Converted.jsp" method="POST">
    Enter Meter Amount: <input type="text" name="metricamount" value="" />
    <br>
    Enter Yard Amount: <input type="text" name="imperialamount" value="" />
    <br>
    <input type="submit" value="Submit" /><br>

    </form>
    </body>

    This is the page it goes to once the user hits the submit button

    <title>Metric and Imperial converter</title>
    </head>
    <body>
    <h1>Converted Values</h1>
    <%!
    private MyConverterRemote converter = null;
    public void jspInit() {
    try {
    InitialContext ic = new InitialContext();
    converter = (MyConverterRemote)
    ic.lookup(MyConverterRemote.class.getName());
    } catch (Exception ex) {
    System.out.println("Couldn't create converter bean." + ex.getMessage());
    }
    }
    public void jspDestroy() {
    converter = null;
    }
    %>
    <%
    String MetricAmount = request.getParameter("metricamount");
    String ImperialAmount = request.getParameter("imperialamount");
    if (MetricAmount != null && MetricAmount.length() > 0) {
    BigDecimal d = new BigDecimal(MetricAmount);

    BigDecimal metAmount = converter.MetrictToImp(d);



    %>
    <p>
    <%= MetricAmount %> Meters are <%= metAmount %> Yards
    <p>
    <%
    BigDecimal e = new BigDecimal(ImperialAmount);

    BigDecimal impAmount = converter.MetrictToImp(e);
    %>
    <p>
    <%= ImperialAmount %> Yards are <%= impAmount %> Meters
    <p>
    <%
    }
    %>
    </body>

    When this page loads I get this exception

    org.apache.jasper.JasperException: java.lang.NullPointerException
    root cause

    java.lang.NullPointerException

    If anyone can point me to the right direction it would be awesome

    Thanks!

  2. #2
    unaTRASotra is offline Member
    Join Date
    Nov 2011
    Posts
    5
    Rep Power
    0

    Default Re: Getting a null pointer exception when loading my JSP result page

    you are retrieving a null converter and when you try BigDecimal impAmount = converter.MetrictToImp(e) the NullPointerException fires

    check the code where you get the converter:
    converter = (MyConverterRemote)ic.lookup(MyConverterRemote.cla ss.getName());

    it is possible in your context there is no such an object

Similar Threads

  1. Null pointer exception
    By jessie in forum New To Java
    Replies: 5
    Last Post: 02-08-2011, 03:58 PM
  2. Null pointer Exception
    By peiceonly in forum New To Java
    Replies: 8
    Last Post: 09-05-2010, 07:48 PM
  3. Null pointer exception
    By talha06 in forum JDBC
    Replies: 5
    Last Post: 07-14-2009, 02:12 AM
  4. Null Pointer Exception
    By andre1011 in forum Advanced Java
    Replies: 4
    Last Post: 02-07-2009, 04:30 AM
  5. Null Pointer Exception
    By demiser55 in forum New To Java
    Replies: 1
    Last Post: 09-22-2008, 07:33 PM

Posting Permissions

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