IllegalArgumentException:Java中的参数类型不匹配

时间:2013-10-15 19:23:21

标签: java observer-pattern

我创建了这段代码,用于通知观察者我的程序。但是当我调用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)

提前致谢!

1 个答案:

答案 0 :(得分:0)

JPanel方法

中的接缝modify()参数不能为空
((RemoteObserver) arrLocal[i]).modify(this, ob)

UPD 哇,您正尝试通过网络服务向JPanel发送一些非Serializable组件。可能你应该只发送一些参数。