2012-04-06 13 views
0

Ich versuche, eine Enterprise-Anwendung zu machen, aber mit einem sehr seltsamen Fehler konfrontiert.Java EE - InvocationTargetException beim Aufruf von Remote Facade erhalten?

Immer wenn ich versuche, die Fassade einer Unternehmensanwendung von einer anderen Klasse als Main aufzurufen, erhalte ich eine InvocationTargetException.

Hier ist mein 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-Klasse: -

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()); 
    } 
} 

} 

Methode 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 

Warum ist das so? und manchmal rufe ich sogar die remote-Methode von meiner Haupt-Klasse an, es gibt mir immer noch diese Ausnahme. Was ist los mit Netbeans? Manchmal funktioniert es irgendwann nicht. Bitte helfen Sie und klären Sie meine Verwirrung.

+1

Der Stapel besagt, dass die InvoicationTargetException von einer NPE verursacht wird, Sie müssen von dort starten. – perissf

Antwort

0

Gemäß this stackoverflow discussion und der referenzierten EJB-Spezifikation ist static Injektion nur in der Anwendungsklasse zulässig. Daher funktioniert die Injektion für Ihre TellerMachine Klasse aber nicht für die TestClass Instanz aus der TellerMachinemain Methode.