The Artima Developer Community
Sponsored Link

Java Answers Forum
Exception while creating instance of EJB

6 replies on 1 page. Most recent reply: Oct 31, 2003 3:23 AM by Joe Parks

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
sanjana

Posts: 4
Nickname: sanjana
Registered: Oct, 2003

Exception while creating instance of EJB Posted: Oct 30, 2003 6:27 PM
Reply to this message Reply
Advertisement
hi,
i m trying to create instance of ejb in client but getting Null pointer exception.

In home interface PlayerHome,create method defined is as follows

..
public LocalPlayer create(String id, String name, String position, double salary) throws CreateException;
..

and in Bean i have set values as follows
..
..
public String ejbCreate (String id, String name, String position, double salary) throws CreateException {

Debug.print("PlayerBean ejbCreate");
setPlayerId(id);
setName(name);
setPosition(position);
setSalary(salary);
return null;
}

.
.
now i m cretaing instance in client program as follows
..
LocalPlayer ac = (LocalPlayer) PortableRemoteObject.narrow(home.create("nxyz123","xyz","football",500.0), PlayerHome.class);
..
and while executing client code i m getting null pointer exception.How can it be solved.
Any help will be appreciated.
thanks


Senthilnathan

Posts: 13
Nickname: ssnathan
Registered: Jul, 2003

Re: Exception while creating instance of EJB Posted: Oct 30, 2003 6:34 PM
Reply to this message Reply
Can you just check whether your 'home' object is null or not null once..

sanjana

Posts: 4
Nickname: sanjana
Registered: Oct, 2003

Re: Exception while creating instance of EJB Posted: Oct 30, 2003 6:41 PM
Reply to this message Reply
Hi,
I m creating instance of ejb in client code which is as follows.



LocalPlayer ac = (LocalPlayer) PortableRemoteObject.narrow(home.create("nxyz123","xyz","football",500.0), PlayerHome.class);

where LocalPlayer is remote interface and home is reference for homeinterface.

so i m passing values to create method.then why i m getting null pointer exception while executing client code.

Senthilnathan

Posts: 13
Nickname: ssnathan
Registered: Jul, 2003

Re: Exception while creating instance of EJB Posted: Oct 30, 2003 6:50 PM
Reply to this message Reply
I just want you to verify that your home object is not null.
If it is null, just verify ur jndi url (whether the port mentioned in the webserver layer is the same as that defined in the app server config file.) and also the JNDI name given for that ejb.

If it is not null, we'll consider the other possibilities.

Object home = ctx.lookup(JNDI_NAME);
PlayerHome playerHome = (PlayerHome) PortableRemoteObject.narrow(home,PlayerHome.class);

if( playerHome == null )
{
System.out.println( "Home Object is null!" );
}

(PlayerParms) PortableRemoteObject.narrow(playeHome.create("nxyz123","xyz","football",500.0), PlayerHome.class);

sanjana

Posts: 4
Nickname: sanjana
Registered: Oct, 2003

Re: Exception while creating instance of EJB Posted: Oct 30, 2003 7:03 PM
Reply to this message Reply
Thanks for help but playerHome is not null.

Senthilnathan

Posts: 13
Nickname: ssnathan
Registered: Jul, 2003

Re: Exception while creating instance of EJB Posted: Oct 30, 2003 7:08 PM
Reply to this message Reply
I guess your posting has the example code.

So, can you just tell me where exactly is the null pointer exception. one of your parameter might be null.. The exception should arise on the client side, as there is no remoteexception of anything.

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: Exception while creating instance of EJB Posted: Oct 31, 2003 3:23 AM
Reply to this message Reply
The code should be
// perform a lookup for the Home
InitialContext context = new InitialContext();
Object homeObject = context.lookup(PLAYERHOMEJNDINAME);
 
// narrow the jndi reference
PlayerHome home = (PlayerHome) PortableRemoteObject.narrow(homeObject, PlayerHome.class);
 
// call create.  no need to cast or narrow
// by the way: if this is a remote home, how can it
// create local interfaces?  Or is "LocalPlayer" just
// someone who plays locally?
LocalPlayer player = home.create("nxyz123","xyz","football",500.0);

Flat View: This topic has 6 replies on 1 page
Topic: what should be used where(servlet vs ejb) Previous Topic   Next Topic Topic: servlet exception

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use