aspose file tools*
The moose likes Distributed Java and the fly likes RMI stub is generating errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI stub is generating errors" Watch "RMI stub is generating errors" New topic
Author

RMI stub is generating errors

Tripti Ag
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
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: 39394
    
  28
Welcome to the Ranch

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

Joined: Jul 03, 2009
Posts: 35
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: 39394
    
  28
Thank you for editing the code.

Do you have a class called Object anywhere?
Tripti Ag
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
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
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
I am unable to solve this problem. Can anyone help me? Thanks in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tripti Ag
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
Yes, i have Object.class in my directory
Tripti Ag
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
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: 19718
    
  20

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
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
Thanks Rob, problem is resolved.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

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
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
ok.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI stub is generating errors