Java EventListenerList error (java.lang.IllegalArgumentException: argument type mismatch)

2.2k Views Asked by At

I keep getting an error with EventListener List. Thank you for any help in advance.

I have following class which has EventListenerList and method to add events:

public class ATMImpl extends UnicastRemoteObject implements ATM {
    private EventListenerList listenerList = new EventListenerList();
    ...
    //more code
    ...

    public void addListener(ATMListener atmListener) throws RemoteException {
        listenerList.add(ATMListener.class, atmListener);
    }
}

I have another class with main method and I am trying to add an object to EventListnerList in this class:

public class Client extends UnicastRemoteObject implements ATMListener {
    public static void main(String[] args) {
        ATM atm;

        try {
            ATMFactory factory = (ATMFactory)Naming.lookup("atmfactory");
            atm = factory.getATM();
            Client clientListener = new Client();
            atm.addListener(clientListener);   //error on this line
        } catch (MalformedURLException mue) {
            mue.printStackTrace();
        } catch (NotBoundException nbe) {
            nbe.printStackTrace();
        } catch (UnknownHostException uhe) {
            uhe.printStackTrace();
        } catch (RemoteException re) {
            re.printStackTrace();
        }
    }
}

I am getting following error. After tracking down where the error is generating from, following line is producing the error.

atm.addListener(clientListener);   //error on this line

Error:

Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at com.sun.proxy.$Proxy1.addListener(Unknown Source)
at cscie55.project.Client.main(Client.java:31)
0

There are 0 best solutions below