This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes NullPointer Exception in EJB 3.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "NullPointer Exception in EJB 3.0" Watch "NullPointer Exception in EJB 3.0" New topic

NullPointer Exception in EJB 3.0

Sagun Khatri

Joined: Dec 21, 2007
Posts: 3
I am sorry if someone has already posted this question before. If someone please point me towards the right direction I would be really grateful.

I am writing a very simple EJB 3.0 Session Bean (Stateless) using Netbeans 6 and GlassFish server.

I am trying to invoke the Remote Interface from an Application Client, but I get a NullPointerException. The problem is my Client Application can't find the Remote Interface. Here is my code

*************** Remote Interface *****************
package ejb30;

import javax.ejb.Remote;

public interface StateLessRemote {
public String hello();

************** Stateless Session Bean *************
package ejb30;

import javax.ejb.Stateless;

public class StateLessBean implements StateLessRemote {
public StateLessBean() {}

public String hello()
return "*** Hello World! ***";

*************** Aplication Client ******************
package stateLessClient;

import javax.ejb.EJB;
import ejb30.StateLessRemote;

public class StateLessAppClient
private static StateLessRemote stateLessBean;

public static void main(String[] args)
System.out.println("*** Calling Stateless bean ****");

********** Error from Netbeans *******************
Dec 21, 2007 3:15:12 PM com.sun.enterprise.appclient.MainWithModuleSupport <init>
WARNING: ACC003: Application threw an exception.
at stateLessClient.StateLessAppClient.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
Sagun Khatri

Joined: Dec 21, 2007
Posts: 3
The solution to the above NullPointer Exception in EJB 3.0 is as follows:

1) Create an Enterprise Application Project in NetBeans 6.0

2) Create new Session Bean, write your session bean code in here.

3) Create a Remote Interface, include the method(s) from the above Session Bean.

4) Create a Application Client in Secure-apple-client node.

5) Write an annotation to call the EJB in the application client.

6) In Java EE 5 we are not required to write a deployment descriptor (ejb-jar.xml). However, if we do have security for the application, we need to specify that in the deployment descriptor.
Sagun Khatri

Joined: Dec 21, 2007
Posts: 3
Hello again, please follow this link to the NetBeans 6.0 tutorial on how to create a Secure Enterprise Bean in Java EE 5.
[ December 24, 2007: Message edited by: Sagun Khatri ]
It is sorta covered in the JavaRanch Style Guide.
subject: NullPointer Exception in EJB 3.0
It's not a secret anymore!