[Logo]
Forums Register Login
RMI stub is generating errors
This is my first program on RMI. But some runtime errors are generated when i use rmic tool to generate stub

"RemoteAdd.java"

import java.rmi.*;

public interface RemoteAdd extends Remote{
public double add(double n1, double n2) throws RemoteException;
}




"RemoteAddServer.java"

import java.rmi.*;
import java.rmi.server.*;

public class RemoteAddServer extends UnicastRemoteObject implements RemoteAdd{

public double add(double n1, double n2){
return (n1+n2);
}

public RemoteAddServer() throws RemoteException{}

public static void main(String[] a){
try{
RemoteAddServer service = new RemoteAddServer();
Naming.rebind("AddRemoteService", service);
}catch(Exception ex){ ex.printStackTrace();}
}

}


"RemoteAddClient.java"

import java.rmi.*;

public class RemoteAddServer extends UnicastRemoteObject implements RemoteAdd{

public double add(double n1, double n2){
return (n1+n2);
}

public RemoteAddServer() throws RemoteException{}

public static void main(String[] a){
try{
RemoteAddServer service = new RemoteAddServer();
Naming.rebind("AddRemoteService", service);
}catch(Exception ex){ ex.printStackTrace();}
}

}

When i type "d:\Program Files\Core> rmic RemoteAddServer", i get the following errors

D:\Program Files\Core\RemoteAddServer_Stub.java:33: Incompatible type for declar
ation. Explicit cast needed to convert java.lang.Object to Object.
Object $result = ref.invoke(this, $method_add_0, new java.lang.Objec
t[] {new java.lang.Double($param_double_1), new java.lang.Double($param_double_2
)}, 864055858262779977L);
^
D:\Program Files\Core\RemoteAddServer_Stub.java:34: Invalid cast from Object to
java.lang.Double.
return ((java.lang.Double) $result).doubleValue();
^
2 errors

My .class files have been generated successfully. My all java files reside in "d:\Program Files\Core" directory.
Welcome to the Ranch

Please go back and edit your post to add code tags, otherwise your post is illegible.
 

Tripti Ag wrote:This is my first program on RMI. But some runtime errors are generated when i use rmic tool to generate stub

"RemoteAdd.java"






"RemoteAddServer.java"



"RemoteAddClient.java"



When i type "d:\Program Files\Core> rmic RemoteAddServer", i get the following errors

D:\Program Files\Core\RemoteAddServer_Stub.java:33: Incompatible type for declar
ation. Explicit cast needed to convert java.lang.Object to Object.
Object $result = ref.invoke(this, $method_add_0, new java.lang.Objec
t[] {new java.lang.Double($param_double_1), new java.lang.Double($param_double_2
)}, 864055858262779977L);
^
D:\Program Files\Core\RemoteAddServer_Stub.java:34: Invalid cast from Object to
java.lang.Double.
return ((java.lang.Double) $result).doubleValue();
^
2 errors

My .class files have been generated successfully. My all java files reside in "d:\Program Files\Core" directory.

 
Thank you for editing the code.

Do you have a class called Object anywhere?
No, i have only these three java files in my directory. I tried another program where remote method does not return anything. It ran successfully. So, my problem occurs only when remote method returns something.
I am unable to solve this problem. Can anyone help me? Thanks in advance.
 

Tripti Ag wrote:No, i have only these three java files in my directory.


And what about class files? Is there an old Object.class around?
Yes, i have Object.class in my directory
Is Object.class is the reason for above problem. What should i do next to solve this problem? Thanks in advance.
Delete it. This class file makes the compiler use your own custom Object class instead of java.lang.Object. Since you have no source of it it's probably a remainder of a class you wrote before but then removed.
Thanks Rob, problem is resolved.
You're welcome.

Although quite late I am moving this (solved) thread to our Distributed Java forum. That's where we handle RMI, not here. I should have done that before.
ok.

This thread has been viewed 1594 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 17, 2018 22:35:05.