-1
我正在開發一個使用以下JAVA RMI設置的分佈式系統。Java RMI ClassCast異常
public interface NodeOperations {
/* RMI methods */
public FingerTable getFingerTable() throws RMIException;
}
public class Node implements NodeOperations {
/* Implements all RMI methods */
/* Also holds a object of FingerTable */
FingerTable ft;
}
public class FingerTable {
/* Holds a reference to Node class which has object of 'this' FingerTable */
Node self;
}
所有RMI通信都是通過NodeOperations
接口中存在的方法完成的。有一種方法會返回特定節點的對象FingerTable
。但是,當我從客戶端調用該方法時,我會遇到異常。我該如何解決這個問題?
java.lang.ClassCastException: cannot assign instance of com.sun.proxy.$Proxy5 to field chord.FingerTable.self of type chord.Node in instance of chord.FingerTable
at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2133)
at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1305)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2237)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2155)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2013)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2231)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2155)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2013)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:326)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:175)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
at com.sun.proxy.$Proxy5.getNodeInfo(Unknown Source)
at chord.NodeTest.testTopology(NodeTest.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
即使我這麼認爲,但我已經使所有這些類可序列化。 – Nullpointer
此代碼不會產生此異常。至少缺少兩件事。發佈真實的代碼。 – EJP