2012-09-29 15 views
11

Io uso rmi in Java. tuttavia esiste un'esportazione "oggetto remoto implementa un'interfaccia remota illegale".Eccezione "l'oggetto remoto implementa l'interfaccia remota illegale"?

Ecco il mio codice, qualcuno mi può aiutare?

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

Hai provato a utilizzare UnicastRemoteObject? – Abubakkar

+0

@Abu Perché? Che differenza farebbe? – EJP

risposta

27

Ogni metodo in un'interfaccia Remote deve essere in grado di gettare un RemoteException. L'interfaccia dovrebbe essere:

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

Si potrebbe voler dare un'occhiata al RMI Tutorial.

Problemi correlati