2017-04-07 81 views
-1

執行程序後引發以下異常。爲什麼Java RMI服務器在嘗試運行時顯示錯誤消息?

未解決編制問題:方法綁定(字符串,遠程)在 類型註冊地是不適用的參數(字符串, EmployeeRMIMain)

public static void main(String args[]){ 
     try { 
      EmployeeService obj = new EmployeeService(); 
      Registry r = LocateRegistry.createRegistry(1234); 
      r.bind("Remote", obj); 
     } catch (RemoteException e) { 
      e.printStackTrace(); 
     } catch (AlreadyBoundException e) { 
      e.printStackTrace(); 
     } 
    } 
+0

我想出了這個問題。 – KMuir

+0

否。下面的*錯誤信息*是*打印*,這是*而不是*程序的執行。 – EJP

回答

0

編輯:用戶已經解決了他自己的問題。 @KMuir即使您找到解決方案,也可以發佈解決方案。

EmployeeService類的類接口是什麼?你確定它實現了遠程標記界面嗎?

public interface TunnelingMessageBox extends Remote { 
    public void pushMessage(Message message) throws RemoteException; 
    //..more interface methods 
} 

public class TunnelingMessageBoxImpl implements TunnelingMessageBox { 
    public void pushMessage(Message message) throws RemoteException { 
    // does the magic 
    } 
} 

public class MyService { 
    private Registry registry; 
    private int port; 
    public void createRegistry(int port) throws RemoteException { 
     Registry reg; 
     try { 
      reg = LocateRegistry.createRegistry(port); 
     } catch (ExportException ex) { 
      // get existing registry instance. 
      reg = LocateRegistry.getRegistry(port); 
     } 
     this.port=port; 
     registry = reg; 
    } 

    public vooid closeRegistry() { 
    try { 
     Remote obj = (Remote)registry.lookup("box1"); 
     UnicastRemoteObject.unexportObject(obj, true); 
     registry.unbind("box1"); 
    } catch(Exception ex) { ex.printStacktrace(); } 
    registry=null; 
    } 

    public void registerServices() throws RemoteException { 
    TunnelingMessageBoxImpl mbox = new TunnelingMessageBoxImpl(); 
    UnicastRemoteObject.exportObject(mbox, port); 
    registry.rebind("box1", mbox); 
    } 

} 
+0

我已經對最初發布的代碼進行了更正。問題是我正在創建一個錯誤類的對象。我在上面的代碼中創建了這個類的一個對象(EmployeeRMIMain),而不是更新的EmployeeService類。發生此錯誤是因爲EmployeeRMIMain方法不從以下UnicastRemoteObject類繼承。 – KMuir

0

我已經對最初發布的代碼進行了更正。問題是我正在創建一個錯誤類的對象。

我在上面的代碼中創建了這個類的對象(EmployeeRMIMain)而不是更新的EmployeeService類。發生此錯誤是因爲EmployeeRMIMain方法不從以下UnicastRemoteObject類繼承。

相關問題