File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes null pointer exception on jndi session bean call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "null pointer exception on jndi session bean call" Watch "null pointer exception on jndi session bean call" New topic

null pointer exception on jndi session bean call

Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 275
Hello. If somebody has a minute, I think I am having trouble getting a handle on a session bean via jndi. This is the session portion of a session-facade that I'm tinkering with (this began with a session bean example I found on the web, but instead of using the servlet and a direct entity bean call, I went for jsp and a session facade). The call to the session facade is located within a javabean that is loaded by jsp...

package com.turtle;

import java.sql.*;
import java.util.*;
import java.text.*;

public ArrayList runQuery() {

try {

javax.naming.InitialContext ctx = new javax.naming.InitialContext();

Object obj = ctx.lookup("TurtleFacade");

if(obj == null) {

System.out.println("OBJ IS NULL");

TurtleFacadeHome home = (TurtleFacadeHome)javax.rmi.PortableRemoteObject.narrow(obj, TurtleFacadeHome.class);

if(home == null) {

System.out.println("HOME IS NULL");
TurtleFacade tf = home.create();

System.out.println("It worked");
ArrayList turtle_array = tf.getTurtleEntity();

return turtle_array;

} catch (Exception e) {


return null;





I kept receivng a null pointer exception and after putting in these print statements, I am finding that the obj is null, pretty much right at the start of the call, it fails (OBJ IS NULL is printed to the console).

Is there something I am missing that should go into the web.xml for this application? I've been looking all over and can't get a definitive picture so far. Here is my web.xml...

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

<web-app xmlns="">
<driver type="oracle.jdbc.driver.OracleDriver">
<url>jdbc :0racle:thin:@sbdoracle:1521 :0racle</url>

<ejb-server config-directory="WEB-INF">


Thank you very much for reading this and thank you for any help.
[ March 07, 2005: Message edited by: Tom Griffith ]
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 275
oh, and here is the session snippet of my deployment descriptor...


thank you again for reading this. I'll keep plugging at this and if I can get this going, I'll post what I did. Thank you for any help...
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Tom,

There are several things that I could suggest to you:
  • Make sure that your session bean was deployed properly.
  • Make sure the bean binds to the JNDI tree within the right context name (your server might have useful tools that can help you doing these two).
  • Make sure that you actually are not declaring ejb references because in that case you might lookup your bean like this:

  • Without being a resin user I�m littele bit intrigued by this declaration:

  • Which looks to me like a resin specific tag. Could this change the naming context for your beans? If the answer is yes then you might need to look up your bean like this:

    Which is a similar technique to using ejb references. Again having a snapshot of your server�s JNDI tree will help you run out this theory.

    See if any of these help.

    I think, therefore I exist -- Rene Descartes
    Tom Griffith
    Ranch Hand

    Joined: Aug 06, 2004
    Posts: 275
    Thank you Valentin. This did the trick...

    Object obj = ctx.lookup("java:comp/env/cmp/TurtleFacade");

    I think my problem is that I tend to associate ejb references with CMP entities. For whatever reason, I tend to forget about them with session beans.
    I agree. Here's the link:
    subject: null pointer exception on jndi session bean call
    It's not a secret anymore!