I'm trying to run this simple and small application but I don't understand which is the problem and consequently how to fix it.
Here it is the code. It is very simple. One bean invoked by a client application in order to print out in the client terminal the well-known message Hello World. I have created the application by using Intellij Idea 13.0.3 IDE with Server GlassFish 4.0.0, Java JDK 8.0. May you explain me step-by-step what I should do to run this application in the ide?
package myejb;import javax.ejb.Remote;@RemotepublicinterfaceHello{ publicString sayHello(String name);}
package myejb;import javax.ejb.Remote;import javax.ejb.Stateless;@Stateless(name ="HelloEJB")@Remote({Hello.class})publicclassHelloBeanimplementsHello{ publicHelloBean() { } @Override publicString sayHello(String name) { return"Hello, "+ name +"!"; }}
and the Client application
package myejbclient;import javax.ejb.EJB;import myejb.Hello;publicclassHelloClient{ @EJB(lookup ="HelloEJB") privatestaticHello hello; publicHelloClient() { } publicstaticvoid main(String[] args) { HelloClient client =newHelloClient(); client.doConversation(); } publicvoid doConversation() { System.out.println(hello.sayHello("World")); }}
I execute glassfish to deploy the application. it is deployed correctly but when I run the client application I get this error message:
Exceptionin thread "main" java.lang.NullPointerException at myejbclient.HelloClient.doConversation(HelloClient.java:27) at myejbclient.HelloClient.main(HelloClient.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)