I am calling my Ejb bean from My Test class.In test class i am using static keyword in front of here userService because i am accessing the userService from the static context(from main method.)
Note: Also If i donot uses the static keyword in front of userService then also i got same error.
public class Test {
@Inject
private static UserService userService;
public Test() {
// TODO Auto-generated constructor stub
}
public static void main(String args[]){
userService.doSomething("hello");
}
}
I setup an EJB 3 interface/implementation looking like this...
UserService (interface)
package business;
public interface UserService {
public String doSomething();
}
UserServiceBean (implementation)
@Stateless
@Local
public class UserServiceBean implements UserService{
public UserServiceBean() {
}
@Override
public String doSomething() {
return "Work done!";
}
}
When i am calling doSomething method of UserServiceBean class using interface from my Test class. Its giving me error like this.
Exception in thread "main" java.lang.NullPointerException
at test.Test.main(Test.java:17)
Please explain me why this error is coming.