I am trying to make an Enterprise Application but facing a very strange error.
Whenever i try to call enterprise application's facade from any class other than Main, I am get an InvocationTargetException.
Here is my code: -
public class TellerMachine {
@EJB
private static BillerFacadeRemote billerFacade;
@EJB
private static AccountFacadeRemote accountFacade;
@EJB
private static CustomerFacadeRemote customerFacade;
@EJB
private static BanktellerFacadeRemote banktellerFacade;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
TellerMachine tm = new TellerMachine();
Scanner s = new Scanner(System.in);
String sssa = billerFacade.hiHAHAHAHA();
System.out.println(sssa);
tm.printABC();
TestClass t = new TestClass();
t.abc();
}
public void printABC()
{
String sssa = billerFacade.hiHAHAHAHA();
System.out.println(sssa);
}
}
Test Class: -
public class TestClass
{
@EJB
private static BillerFacadeRemote billerFacade;
public static void main(String[] args)
{
}
public void abc()
{
try{
String a = billerFacade.hiHAHAHAHA();
System.out.println(a);}
catch(Exception e)
{
System.out.println(e.getCause().toString());
}
}
}
Method in BillerFacade: -
@Override
public String hiHAHAHAHA() {
return "abc";
}
Stack Trace: -
Warning: /Users/varunbatra/Desktop/RealApp/SwinBankTellerMachine/dist/gfdeploy/SwinBankTellerMachine does not exist.
abc
abc
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:438)
at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:165)
Caused by: java.lang.NullPointerException
at swinbanktellermachine.TestClass.abc(TestClass.java:29)
at swinbanktellermachine.TellerMachine.main(TellerMachine.java:52)
... 6 more
Java Result: 1
Why it's like that? and sometime even i am calling the remote method from my Main class it still gives me this Exception. What's the matter with Netbeans? Sometime it works sometime it doesn't. Please Help and clear my confusion.