Java RMI Proxy issue

Posted by Antony Lewis on Stack Overflow See other posts from Stack Overflow or by Antony Lewis
Published on 2010-05-12T18:41:33Z Indexed on 2010/05/12 18:44 UTC
Read the original article Hit count: 229

Filed under:
|
|

i am getting this error : java.lang.ClassCastException: $Proxy0 cannot be cast to rmi.engine.Call at Main.main(Main.java:39)

my abstract and call class both extend remote.

call:

public class Call extends UnicastRemoteObject implements rmi.engine.Abstract {

public Call() throws Exception {
    super(Store.PORT, new RClient(), new RServer());
}

public String getHello() {
    System.out.println("CONN");
    return "HEY";
}

}

abstract:

public interface Abstract extends Remote {

String getHello() throws RemoteException;

}

this is my main:

public static void main(String[] args) {
    if (args.length == 0) {

        try {
            System.out.println("We are slave ");
            InetAddress ip = InetAddress.getLocalHost();
            Registry rr = LocateRegistry.getRegistry(ip.getHostAddress(), Store.PORT, new RClient());

            Object ss = rr.lookup("FILLER");

            System.out.println(ss.getClass().getCanonicalName());

           System.out.println(((Call)ss).getHello());

        } catch (Exception e) {
            e.printStackTrace();
        }

    } else {

        if (args[0].equals("master")) {

            // Start Master

            try {

                RMIServer.start();

            } catch (Exception e) {
                e.printStackTrace();

            }
        }

Netbeans says the problem is on line 39 which is

    System.out.println(((Call)ss).getHello());

the output looks like this:

run:

We are slave

Connecting 10.0.0.212:5225

$Proxy0

java.lang.ClassCastException: $Proxy0 cannot be cast to rmi.engine.Call at Main.main(Main.java:39)

BUILD SUCCESSFUL (total time: 1 second)

i am running a master in cmd listening on port 5225.

© Stack Overflow or respective owner

Related posts about java

Related posts about rmi