2012-09-29 22 views
11

Uso rmi en Java. sin embargo, hay una ExportException "objeto remoto que implementa una interfaz remota ilegal".Excepción "objeto remoto implementa interfaz remota ilegal"?

Aquí está mi código, ¿alguien puede ayudarme?

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

¿Ha intentado utilizar UnicastRemoteObject? – Abubakkar

+0

@Abu ¿Por qué? ¿Qué diferencia haría eso? – EJP

Respuesta

27

Cada método en una interfaz de Remote debe ser capaz de lanzar una RemoteException. Su interfaz debe ser:

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; 
} 

Es posible que desee echar un vistazo a la RMI Tutorial.

Cuestiones relacionadas