我创建了这段代码,用于通知观察者我的程序。但是当我调用notfyObservers()方法时,它会给我错误。这是Java RMI计划。
IllegalArgumentException:Java中的参数类型不匹配
notifyObserver()方法:
@Override
public void notifyObservers(JPanel ob) throws RemoteException {
Object[] arrLocal;
synchronized (this) {
if (!changed) {
return;
}
arrLocal = listObs.toArray();
clearChanged();
}
for (int i = arrLocal.length - 1; i >= 0; i--) {
((RemoteObserver) arrLocal[i]).modify(this, ob);
}
}
被称为..
questionController.notifyObservers(null);
我在JPanel
中调用此方法,而我的错误是在我通过jpanel时...
java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.io.NotSerializableException: javax.swing.GroupLayout
如果我通过null,我得到了。
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
提前致谢!
答案 0 :(得分:0)
JPanel
方法
modify()
参数不能为空
((RemoteObserver) arrLocal[i]).modify(this, ob)
UPD 哇,您正尝试通过网络服务向JPanel
发送一些非Serializable
组件。可能你应该只发送一些参数。