| Author |
RMI stub is generating errors
|
Tripti Ag
Greenhorn
Joined: Jul 03, 2009
Posts: 10
|
|
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.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32645
|
|
Welcome to the Ranch
Please go back and edit your post to add code tags, otherwise your post is illegible.
|
 |
Tripti Ag
Greenhorn
Joined: Jul 03, 2009
Posts: 10
|
|
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.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32645
|
|
Thank you for editing the code.
Do you have a class called Object anywhere?
|
 |
Tripti Ag
Greenhorn
Joined: Jul 03, 2009
Posts: 10
|
|
|
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.
|
 |
Tripti Ag
Greenhorn
Joined: Jul 03, 2009
Posts: 10
|
|
|
I am unable to solve this problem. Can anyone help me? Thanks in advance.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Tripti Ag
Greenhorn
Joined: Jul 03, 2009
Posts: 10
|
|
|
Yes, i have Object.class in my directory
|
 |
Tripti Ag
Greenhorn
Joined: Jul 03, 2009
Posts: 10
|
|
|
Is Object.class is the reason for above problem. What should i do next to solve this problem? Thanks in advance.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
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.
|
 |
Tripti Ag
Greenhorn
Joined: Jul 03, 2009
Posts: 10
|
|
|
Thanks Rob, problem is resolved.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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.
|
 |
Tripti Ag
Greenhorn
Joined: Jul 03, 2009
Posts: 10
|
|
|
ok.
|
 |
 |
|
|
subject: RMI stub is generating errors
|
|
|