【问题标题】:Java RMI ClassCastException [duplicate]Java RMI ClassCastException [重复]
【发布时间】:2018-08-15 01:12:14
【问题描述】:

我得到了错误

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

when(导致问题的第二行)

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

}

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-03-14
      • 2021-08-14
      • 2016-04-01
      • 1970-01-01
      • 2016-09-01
      • 1970-01-01
      • 2016-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多