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;
}
注意:所有需要描述和回答問題的信息都必須包含在問題本身中。你提供的pastebin鏈接是無意義的浪費時間。 – EJP 2014-12-02 02:05:52
@RambabuMandalapu刪除的答案確實是一個答案。只是一個錯誤的答案。奇怪的評論。 – EJP 2016-10-10 07:42:31