2014-06-24 100 views
1

嗨,我不斷收到這個錯誤,不知道爲什麼ClassCastException異常:Proxy0不能轉換到interfaces.Patient

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

其在客戶端和服務器端的相同也包名稱是t他一樣;

這裏的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(); 
     } 
     } 

    } 

我究竟做錯了什麼?會很高興如果有人有想法

+0

接口的輸入在哪裏?在MainServer中*是什麼?Patient和PatientImpl是什麼樣的? – EJP

回答

2

您的Patient接口應該擴展接口java.rmi.Remote,使其在遠程端可用。

相關問題