This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Mastering Corda: Blockchain for Java Developers and have Jamiel Sheikh on-line!
See this thread for details.
Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

can't get this little RMI program to run...

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,
I have a little problem with this simple RMI program...

Here the 4 classes:
--------------------------------------------------------------
import java.rmi.*;

public interface remoteInterface extends Remote {
public void printLosung() throws RemoteException;
}
--------------------------------------------------------------
import java.rmi.*;
import java.rmi.server.*;

public class server {
public static void main(String[] args) {
try {
remoteObject obj = new remoteObject();
Naming.rebind("Tageslosung", obj);
} catch (Exception e) {
e.printStackTrace();
}
}
}
--------------------------------------------------------------
import java.rmi.*;
import java.rmi.server.*;

public class remoteObject extends UnicastRemoteObject implements remoteInterface {
public remoteObject() throws RemoteException {}
public void printLosung() {
System.out.println("text");
}
}
--------------------------------------------------------------
public class client {
public static void main(String[] args) {
//System.setSecurityManager(new RMISecurityManager());

try {
remoteObject obj = (remoteObject) Naming.lookup("rmi://localhost/Tageslosung");
obj.printLosung();
} catch (Exception e) {
e.printStackTrace();
}
}
}
--------------------------------------------------------------
After compiling, rmic-ing the remote object and registering it, I start server and client, but client gives me the message "ClassCastException" in the client class (obviously because of that remote object). But well, I don't get it really, I mean why? How should I do it then?
Thanks a lot for your help
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tobias Koch:
remoteObject obj = (remoteObject) Naming.lookup("rmi://localhost/Tageslosung");

When working with remote objects, you should use their interfaces instead of the classes. Try this instead:The reason is that the object returned from lookup() is not a remoteObject but a new class, created by rmic, that implements remoteInterface with methods that make remote calls to the RMI server.
[ January 17, 2005: Message edited by: David Harkness ]
 
Tobias Koch
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David,
thanks for your reply!
At compile-time I now get the following error message:

"remoteInterface is abstract; cannot be instantiated"

What to do?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like you switched from the implementation to the interface in the server side code... this should be done in the client side code, not the server.
 
Arthur, where are your pants? Check under this tiny ad.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic