<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    java.lang.NullPointerException in EJB3 from JSP page
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/mmunir">Moazzam Munir</a> in <i>EJB3 Development</i> - <a href="https://community.jboss.org/message/649905#649905">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p style="margin-bottom: 1em;">I am developing my first EJB 3 application using JBOSS 7 as application server in Eclipse. The session bean is deployed successfully on the server but when i try to access it from the JSP page, then i get the java.lang.NullPointerException exception.</p><p style="margin-bottom: 1em;">Following is my code:</p><p style="margin-bottom: 1em;"><strong>Local Interface</strong>:</p><p style="margin-bottom: 1em; padding-left: 60px;"><code style="background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">package my.first;<br/><br/>import javax.ejb.Local;<br/><br/>@Local<br/>public interface CalculatorRemote {<br/><br/>&#160;&#160;&#160;&#160; public float add(float x, float y);<br/><br/>&#160;&#160;&#160;&#160; public float subtract(float x, float y);<br/><br/>&#160;&#160;&#160;&#160; public float multiply(float x, float y);<br/><br/>&#160;&#160;&#160;&#160; public float division(float x, float y);<br/>}</code></p><p><strong style="font-size: 12px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;">Session bean</strong><span style="color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 12px; background-color: #ffffff;">:</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="padding-left: 60px;"><span style="color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 12px; background-color: #ffffff;"><code style="background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">package my.first;<br/><br/>&#160;&#160;&#160; import javax.ejb.LocalBean;<br/>&#160;&#160;&#160; import javax.ejb.Stateless;<br/><br/>&#160;&#160;&#160; @Stateless(name = "CalculatorRemote")<br/>&#160;&#160;&#160; public class CalculatorBean implements CalculatorRemote {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public float add(float x, float y) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return x + y;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public float subtract(float x, float y) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return x - y;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public float multiply(float x, float y) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return x * y;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public float division(float x, float y) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return x / y;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160; }</code><br/></span></p><p style="margin-bottom: 1em;"><strong>JSP Page:</strong></p><p style="margin-bottom: 1em; padding-left: 60px;"><code style="background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">&#160;&#160;&#160;&#160; &lt;%!<br/>&#160;&#160;&#160;&#160;&#160; private CalculatorRemote calculator = null;<br/>&#160;&#160;&#160;&#160;&#160; float result=0;<br/><br/>&#160;&#160;&#160;&#160;&#160; public void jspInit() {<br/>&#160;&#160;&#160;&#160;&#160; try {<br/><br/>&#160;&#160;&#160;&#160;&#160; InitialContext ic = new InitialContext();<br/><br/>&#160;&#160;&#160;&#160;&#160; calculator = (CalculatorRemote) ic<br/>&#160;&#160;&#160;&#160;&#160; .lookup("CalculatorRemote/Local");<br/><br/><br/>&#160;&#160;&#160;&#160;&#160; System.out.println("Loaded Calculator Bean");<br/>&#160;&#160;&#160; //CalculatorBean<br/><br/>&#160;&#160;&#160;&#160;&#160; } catch (Exception ex) {<br/>&#160;&#160;&#160;&#160;&#160; System.out.println("Error:"+<br/>&#160;&#160;&#160;&#160;&#160; ex.getMessage());<br/>&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160; public void jspDestroy() {<br/>&#160;&#160;&#160;&#160;&#160; calculator = null;<br/>&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160; %&gt;</code></p><p style="margin-bottom: 1em;"><strong style="font-size: 12px; background-color: #ffffff; color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;">Server Log File:</strong></p><p style="margin-bottom: 1em; padding-left: 60px;"><code style="background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">17:17:20,552 INFO&#160; [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named CalculatorRemote in deployment unit deployment "EJBsession.jar" are as follows:<br/><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; java:global/EJBsession/CalculatorRemote!my.first.CalculatorBean<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; java:app/EJBsession/CalculatorRemote!my.first.CalculatorBean<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; java:module/CalculatorRemote!my.first.CalculatorBean<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; java:global/EJBsession/CalculatorRemote!my.first.CalculatorRemote<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; java:app/EJBsession/CalculatorRemote!my.first.CalculatorRemote<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; java:module/CalculatorRemote!my.first.CalculatorRemote<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ......<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ......<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ......<br/><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; 17:23:44,105 ERROR [stderr] (http--127.0.0.1-8080-1) java.lang.NullPointerException<br/><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; 17:23:44,105 ERROR [stderr] (http--127.0.0.1-8080-1)&#160;&#160;&#160; at org.apache.jsp.test_jsp._jspService(test_jsp.java:102)<br/><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; 17:23:44,105 ERROR [stderr] (http--127.0.0.1-8080-1)&#160;&#160;&#160; at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)<br/><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; 17:23:44,105 ERROR [stderr] (http--127.0.0.1-8080-1)&#160;&#160;&#160; at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)<br/><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ......<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ......<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ......</code></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="margin-bottom: 1em;"><span style="color: #000000; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 12px; background-color: #ffffff;">Please help?</span></p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/649905#649905">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2030">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>