2012-06-19 141 views
0

下面是我的代碼EJB 2.1 ClassCastException異常

Properties localProperties = new Properties(); 
     localProperties.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory"); 
     localProperties.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming"); 
     localProperties.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"); 
     localProperties.setProperty("org.omg.CORBA.ORBInitialHost", "localhost"); 
     localProperties.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); 
     InitialContext localInitialContext = new InitialContext(localProperties); 
     SanityAutomationAvailabilityMain localSanityAutomationAvailabilityMain = (SanityAutomationAvailabilityMain)localInitialContext.lookup("ejb/com/cw/wad/sanity/ejb/session/interfaces/SanityAutomationAvailabilityMain"); 

我得到與上面的代碼一個ClassCastException。任何想法,我可能做錯了什麼?謝謝。

+1

將**完整堆棧跟蹤**添加到您的問題。 –

+0

什麼是InitialContext?你對我們有什麼期望? –

回答

1

您正在嘗試轉換爲(SanityAutomationAvailabilityMain),並且您得到一個classcastexception,那麼無論您嘗試投射的值是什麼類型,都與SanityAutomationAvailabilityMain不兼容。