gpt4 book ai didi

java - ClassCastException : Proxy0 cannot be cast to interfaces. 患者

转载 作者:行者123 更新时间:2023-11-30 03:51:20 28 4
gpt4 key购买 nike

嗨,我不断收到此错误,但不知道为什么

java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to interfaces.Patient
at main.RemoteObjects.<init>(RemoteObjects.java:15)
at DRV_GUI.<init>(DRV_GUI.java:49)
at Main.main(Main.java:13)

我有一个像这样启动的服务器应用程序:

import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class MainServer {

PatientImpl patient = null;
LoginImpl login = null;

public MainServer(String[] args) {
// TODO constructor
System.out.println("Ich bin der Konstruktor von Main.java");
}

public static void main(String[] args) {
MainServer server = new MainServer(args);
server.start();
}

private void start() {
try {
patient = new PatientImpl();
login = new LoginImpl();
Registry registry = LocateRegistry.createRegistry(1099);
Naming.rebind("patient", patient);
Naming.rebind("login", login);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

患者界面如下:

package interfaces;

import java.rmi.RemoteException;
import java.util.LinkedHashMap;

public interface Patient {
public LinkedHashMap<String, LinkedHashMap<Integer, LinkedHashMap<String, Object>>> patientSuchen(String id, User user) throws RemoteException;
public boolean kostenzusageSpeichern (String id, User user) throws RemoteException;
public boolean aufnahmeStornieren (String id, User user) throws RemoteException;
public boolean aufnahmeAendern (String id, User user) throws RemoteException;
public boolean entlassungStornieren (String id, User user) throws RemoteException;
public boolean entlassungAendern (String id, User user) throws RemoteException;
public boolean eingangEntlassungsStatistikStorieren (String id, User user) throws RemoteException;
public boolean eingangEntlassungsStatistikAendern (String id, User user) throws RemoteException;
public LinkedHashMap<String, LinkedHashMap<String, Object>> getVeraengerunglUnterbrechung(String id, String table, User user) throws RemoteException;
public boolean setVeraengerunglUnterbrechung(String id, String table, User user) throws RemoteException;
}

客户端和服务器端相同,包名也相同;

这里是RemoteObjects.java代码:

    package main;

import interfaces.*;
import java.rmi.Naming;

public class RemoteObjects {
Login login;
public Patient patient;
public String remoteIP = "127.0.0.1";

/*
* secrets[0] = PatientI
*/
public RemoteObjects() {
try {
String name = "rmi://" + remoteIP + ":" + 1099 + "/";
patient = (Patient) Naming.lookup(name + "patient");
login = (Login) Naming.lookup(name + "login");
} catch (Exception ex) {
ex.printStackTrace();
}
}

}

我做错了什么?如果有人有想法,我会很高兴

最佳答案

您的Patient接口(interface)应扩展接口(interface)java.rmi.Remote以使其在远程端可用。

关于java - ClassCastException : Proxy0 cannot be cast to interfaces. 患者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24382441/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com