2011-02-08 68 views
0

我有folloving RMI服務器:RMI無法找到綁定的對象?

public static void main(String[] args) { 
    try{ 
     ChatSystemImpl chatSystem = new ChatSystemImpl(); 
     ChatSystem chatSystem_stub = (ChatSystem) UnicastRemoteObject.exportObject(chatSystem, 6001); 

     Registry registry = LocateRegistry.getRegistry("localhost", 6001); 
     registry.bind("ChatSystem1", chatSystem_stub); 

     System.out.println("Server up."); 
    } 
    catch(Exception ex){ 
     ex.printStackTrace(); 
    } 
} 

當我運行它,我得到:

ava.rmi.NoSuchObjectException: no such object in table 
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273) 
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251) 
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377) 
    at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source) 
    at fr.inp.ensimag.examples.chatsystem.Main.main(Main.java:30) 

嗯,我不知道什麼是錯......它凝視更多2小時,然後馬上。

這是接口(如果需要):

public interface ChatSystem extends Remote{ 
    void registerUser(UserInfo newUser) throws RemoteException; 
    void unregisterUser(UserInfo user) throws RemoteException; 
    boolean userExists(UserInfo user) throws RemoteException; 
    void send(MessageInfo message) throws RemoteException; 
} 

的實施,如下頭,身體只包含未真正落實,他們只是thow UnsupportedOperationException方法:

public class ChatSystemImpl implements ChatSystem 

ChatSystem接口在其他項目中,然後是源代碼的其餘部分,如果它是任何重要的。

謝謝。

回答

0

您的註冊表已被取消導出。這通常意味着你通過LocateRegistry.createRegistry()在JVM中運行它,並且讓它變成垃圾收集。該方法的結果應該存儲在一個靜態變量中。這也可能意味着你從未開始註冊表。