• Post Reply Bookmark Topic Watch Topic
  • New Topic

RMI- Problem with Serialization  RSS feed

 
Saskia Schreiber
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I'm just testing some RMI-programms. I wrote an ServerImpl which got the method getJFrame() (it returns an JFrame) I've got the Interface which is extended from the RemoteInterface but when I want to start the Server it always brings me these errors:
java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.io.NotSerializableException: de.xx.test.ServerImpl
java.io.NotSerializableException: de.xx.test.ServerImpl
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
error marshalling arguments; nested exception is:
java.io.NotSerializableException: de.xx.test.ServerImpl
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at de.xx.test.ServerImpl.main(ServerImpl.java:31)
and here is my ServerImpl:
public class ServerImpl implements Saskia {
public ServerImpl() {
}
public JFrame getJFrame() throws RemoteException {
JFrame myFrame = new JFrame("Saskia's Test");
myFrame.setBackground(Color.blue);
myFrame.setBounds(100,100,100,100);
return myFrame;
}
public static void main(String[] args){
try {
ServerImpl si= new ServerImpl();
Naming.rebind("rmi://dpc04:7011/Server",(Remote)si);
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println(ex.getLocalizedMessage());
}
}
}
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFrame is not serializable. A frame represents an OS resource and cannot be sent over the network. In general, things like GUI widgets, database connections and the like cannot be serialized and so cannot be passed into or returned from an RMI method.
- Peter
 
Saskia Schreiber
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I implemented the interface Serializable to my Server-programm and now it's working fine (after I also added a RMISecurityManager to my program). I got a beautiful JFrame on the client although most RMI-books say that JFrame is not transportable over network... :-)
 
Marco Barenkamp
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
remember that the client only got a copy of the original frame
created on the server and not the object itself.
Implementing Serializable in RMI means 'passByValue'
------------------
Marco Barenkamp
____________________________________________
L M I N T E R N E T S E R V I C E S AG
Senior Trainer & Architect,
BEA Certified Enterprise Developer
Sun Certified Programmer for the Java2 Platform
Sun Certified Web Component Developer for the Java2 Platform
Sun Certified Developer for the Java 2 Platform
Sun Certified Enterprise Architect for the Java 2 Platform Enterprise Edition (PI)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!