0

我正在尝试制作一个企业应用程序,但面临一个非常奇怪的错误。

每当我尝试从除 Main 之外的任何类调用企业应用程序的外观时,我都会收到 InvocationTargetException。

这是我的代码: -

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

测试等级:-

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

}

BillerFacade 中的方法:-

@Override
public String hiHAHAHAHA() {
    return "abc";
}

堆栈跟踪: -

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

为什么会这样?有时即使我从我的 Main 类调用远程方法,它仍然给我这个异常。Netbeans 怎么了?有时它起作用有时它不起作用。请帮助并清除我的困惑。

4

1 回答 1

0

根据这个 stackoverflow 讨论和引用的 EJB 规范,static注入只允许在应用程序主类中。因此,注入适用于您的类,但不适用于方法内的TellerMachine调用实例。TestClassTellerMachine main

于 2012-04-07T13:22:20.953 回答