Reputation: 33
Hi i keep getting this error and don't know why
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)
I have a server application starting like this:
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();
}
}
}
the patient interface ís the follówing:
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;
}
its the same on client and server side also the package name is the same;
here the RemoteObjects.java code:
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();
}
}
}
what am I doing wrong? would be very happy if somebody has an idea
Upvotes: 1
Views: 6710
Reputation: 31299
Your Patient
interface should extend the interface java.rmi.Remote
to make it available on the remote end.
Upvotes: 3