2013-11-24 91 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文件。