2014-12-02 61 views
0

我试图在使用RMI的远程服务器上调用斐波那契方法,但是当我尝试通过给该方法调用一个整数值来调用客户端方法时,出现以下错误:当调用远程方法时出错

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object 
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source) 
    at sun.rmi.transport.Transport$1.run(Unknown Source) 
    at sun.rmi.transport.Transport$1.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at sun.rmi.transport.Transport.serviceCall(Unknown Source) 
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source) 
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source) 
    at sun.rmi.server.UnicastRef.invoke(Unknown Source) 
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source) 
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source) 
    at com.sun.proxy.$Proxy0.fibonacciArrayTest(Unknown Source) 
    at ie.gmit.FibonacciClient.main(FibonacciClient.java:37) 

有没有人有任何想法,我在这个实施出错了?

这是RMI应用程序的客户端:

 //get user input 
     Scanner user_input = new Scanner(System.in); 
     String fibMaxNum; 

     System.out.println("Enter the max fibonacci number: "); 
     fibMaxNum = user_input.next(); 


     int fibMax = Integer.parseInt(fibMaxNum); 

    //Get Fibonacci array. 
    int[] sequence = power_proxy.fibonacciArrayTest(fibMax); 
    for (int value : sequence) { 
     System.out.println(value); 
    } 

而且这是在服务器端执行,我也得到一个错误这里The return type is incompatible with IPower.fibonacciArrayTest(int)。我从这个,我不是指定收集Ipower界面中的正确返回类型,但是如何纠正签名以解决此问题?我应该在Ipower更改方法:

public int[] fibonacciArrayTest(int n) { 

     int a = 0; 
     int b = 1; 
     int[] sequence = new int[n]; 

     // Fill array with Fibonacci values. 
     for (int i = 0; i < n; i++) { 
      sequence[i] = a; 

      int temp = a; 
      a = b; 
      b = temp + b; 
     } 
     return sequence; 
     } 

接口:

public interface IPower extends Remote{ 

    //Declare available methods and must throw RemoteException 
     int[] fibonacciArrayTest(int fibMax) throws RemoteException; 

} 
+1

注意:所有需要描述和回答问题的信息都必须包含在问题本身中。你提供的pastebin链接是无意义的浪费时间。 – EJP 2014-12-02 02:05:52

+0

@RambabuMandalapu删除的答案确实是一个答案。只是一个错误的答案。奇怪的评论。 – EJP 2016-10-10 07:42:31

回答

3

您已经部署后更改您的远程方法的签名。

清理并重建并重新部署到客户端和服务器,不要忘记重新启动注册表。