2017-04-07 79 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类继承。

相关问题