Java RMI ClassCastException

时间:2018-03-07 02:54:31

标签: java ftp network-programming client-server rmi

我收到错误

java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to ServerInterface

何时(导致问题的第二行)

Registry myreg = LocateRegistry.getRegistry(hostname, portnumber);
interOne = (ServerInterface) myreg.lookup(ServerOne);

interOne已被宣布为

private static ServerInterface interOne;

它只是服务器接口的三个实例之一;总共有三个。服务器界面如​​下:

import java.io.File;
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface ServerInterface extends Remote {

    void uploadFileToServer(byte[] mybyte, String serverpath, int length) throws RemoteException;

    byte[] downloadFileFromServer(String servername) throws RemoteException;

    String[] listFiles() throws RemoteException;

    boolean removeDirectoryOrFile(String serverpath) throws RemoteException;

    int directorySize(File directory);

}

1 个答案:

答案 0 :(得分:0)

客户端使用的远程接口在所有方面都必须相同,包括到远程对象导出的远程接口。

两个不同包中的两个接口是不同的,无论它们可能共享的其他相似之处,包括它们的名称。