2012-09-29 35 views
11

Tôi sử dụng rmi trong Java. tuy nhiên có một đối tượng từ xa "ExportException" thực hiện giao diện từ xa bất hợp pháp ".Ngoại lệ "đối tượng từ xa thực hiện giao diện từ xa bất hợp pháp"?

Đây là mã của tôi , Có thể ai đó giúp tôi?

public interface RemotePeer extends Remote { 

    public abstract void displayInf(String inf); 

    public abstract void exit(); 

    public abstract boolean isActive(); 
} 


public class Peer implements RemotePeer{ 
     public Peer(){} 
     .... 

     public static void main(String[] args) { 
      Peer p=new Peer() 
      RemotePeer remoteP=(RemotePeer) UnicastRemoteObject.exportObject(p, 0); 
      Registry registry = LocateRegistry.getRegistry(); 
      } 
} 
+0

Bạn đã thử sử dụng UnicastRemoteObject chưa? – Abubakkar

+0

@Abu Tại sao? Sự khác biệt nào sẽ tạo ra? – EJP

Trả lời

27

Mỗi phương pháp trong một giao diện Remote phải có khả năng ném một RemoteException. Giao diện của bạn phải là:

public interface RemotePeer extends Remote { 

    public abstract void displayInf(String inf) throws RemoteException; 

    public abstract void exit() throws RemoteException; 

    public abstract boolean isActive() throws RemoteException; 
} 

Bạn có thể muốn xem qua số RMI Tutorial.

Các vấn đề liên quan