2013-11-24 117 views
0

我的項目是客戶機/服務器的客戶端發送對象到服務器,服務器響應,所有通過RMIRMI客戶UnmarshalException

客戶端項目

//接口

public interface RMI_INTERFACE extends Remote 
{ 

public int Add(Employee e) throws RemoteException; 
} 

//我需要發送的類

public class Employee implements Serializable 
{ 
int ID; 

String Name; 

int Salary; 

public Employee(int id,String name,int salary) 
{ 
    ID=id; 

    Name =name; 

    Salary=salary; 
} 


} 

//客戶端

public class RMI_CLIENT 
{ 

public RMI_CLIENT() 
{ 

} 

public static void main(String[] args) {  
    try { 


     String name = "RMI_INTERFACE"; 
     Registry registry = LocateRegistry.getRegistry("localhost",5000); 
     RMI_INTERFACE si = (RMI_INTERFACE) registry.lookup(name); 

     int ii; 

     for (Integer i=0 ;i<10;i++) 
     { 
      Employee e= new Employee(i, "employee"+i.toString() , i*1000+100); 

      ii=si.Add(e); 
      System.out.println(ii); 

     } 

     // int pi = si.Get_Salary(s); 


    } catch (Exception e) { 
     System.err.println(e.getCause()); 
    } 
} 
} 

//服務器項目

//接口 公共接口RMI_INTERFACE擴展遠程 {

public int Add(Employee e) throws RemoteException; 
} 

//類,我將它發送和接收它 公共類員工實現Serializable { int ID;

String Name; 

int Salary; 

public Employee(int id,String name,int salary) 
{ 
    ID=id; 

    Name =name; 

    Salary=salary; 
} 


} 

//類來保存所有接收到的對象 公共類Maneger {

static Employee [] employee_arr = new Employee[10]; 

static int i=0; 

Maneger (Employee e) 
{ 
    employee_arr[i]=e; 

    i++; 

} 

public int Get_Index() 
{ 
    return i; 
} 
} 

//服務器 公共類RMI_SERVER擴展了UnicastRemoteObject實現RMI_INTERFACE {

RMI_SERVER() throws RemoteException 
{ 
     super(); 
} 

/** 
* @param args the command line arguments 
*/ 
public static void main(String[] args) { 
    try { 
     // TODO code application logic here   

     String name = "RMI_INTERFACE"; 
     RMI_INTERFACE si = new RMI_SERVER();   
     Registry registry = LocateRegistry.createRegistry(5000); 
     registry.rebind(name, new RMI_SERVER()); 
     System.out.println("Server is running ..."); 




    } 
    catch (Exception e) { 
     System.err.println("ComputeEngine exception:"); 
    } 



} 

@Override 
public int Add(Employee e) throws RemoteException { 

    Maneger m =new Maneger(e); 

    return m.Get_Index(); 

} 


} 

當我運行客戶端出現此錯誤:java.rmi.UnmarshalException:無法識別的方法哈希:方法沒有t由遠程對象支持

回答

0

您已更改遠程對象或遠程接口,但尚未重新編譯和重新部署所有受影響的.class文件。