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

    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

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


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

    <title>Metric and Imperial converter</title>
    <h1>Converted Values</h1>
    private MyConverterRemote converter = null;
    public void jspInit() {
    try {
    InitialContext ic = new InitialContext();
    converter = (MyConverterRemote)
    } 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);

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

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

    When this page loads I get this exception

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


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


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

    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, 02:58 PM
  2. Null pointer Exception
    By peiceonly in forum New To Java
    Replies: 8
    Last Post: 09-05-2010, 06:48 PM
  3. Null pointer exception
    By talha06 in forum JDBC
    Replies: 5
    Last Post: 07-14-2009, 01:12 AM
  4. Null Pointer Exception
    By andre1011 in forum Advanced Java
    Replies: 4
    Last Post: 02-07-2009, 03:30 AM
  5. Null Pointer Exception
    By demiser55 in forum New To Java
    Replies: 1
    Last Post: 09-22-2008, 06: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