• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

NullPointer Exception in EJB 3.0

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;

@Remote
public interface StateLessRemote {
public String hello();
}


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

import javax.ejb.Stateless;

@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
{
@EJB(mappedName="ejb03.StateLessRemote")
private static StateLessRemote stateLessBean;

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


********** Error from Netbeans *******************
Dec 21, 2007 3:15:12 PM com.sun.enterprise.appclient.MainWithModuleSupport <init>
WARNING: ACC003: Application threw an exception.
java.lang.NullPointerException
at stateLessClient.StateLessAppClient.main(StateLessAppClient.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
Sagun Khatri
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again, please follow this link to the NetBeans 6.0 tutorial on how to create a Secure Enterprise Bean in Java EE 5.

http://www.netbeans.org/kb/60/javaee/secure-ejb.html
[ December 24, 2007: Message edited by: Sagun Khatri ]
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic