Java RMI error unmarshalling arguments

Java RMI(Java Remote Method Invocation) is a Java API that performs the object-oriented equivalent of remote procedure calls (RPC), it allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. It provides for remote communication where all participating applications are written by Java.

Today, when I ran a “hello world” example, unfortunately I got the following error messages:

Exception in thread "main" java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.io.NotSerializableException: server.Hello
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at server.HelloServer.main(HelloServer.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.io.NotSerializableException: server.Hello
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
... 8 more

The Java RMI server ran on IDEA9.0 and the Java version is “1.6.0_18″. I confused a lot why this error occurs, my initial understanding was, perhaps, caused by that the JVM engine is not able to detect where are the serialized class or data, but quickly I learned that a required class was missing in classpath.

A Java class can be turned to be remotely accessible by implementing a custom remote interface, it have to extend uka.karmi.rmi.Remote and UnicastRemoteObjectUnicastRemoteObject both, UnicastRemoteObject is exported in constructor, but my remote object has not implemented class UnicastRemoteObject. I extended UnicastRemoteObject for calss Hello then “java rmi error unmarshalling arguments” error was gone.
This is code what the error unmarshalling arguments occurs:

public class Hello implements HelloInterface {
  public Hello() throws RemoteException {
  }

  public String sayHello() throws RemoteException {
    return "good hello";
  }
}

I fixed code as below to resolve error unmarshalling arguments:

public class Hello extends UnicastRemoteObject implements HelloInterface {
  public Hello() throws RemoteException {
  }

  public String sayHello() throws RemoteException {
    return "good hello";
  }

}

Rate article
ASJAVA.COM
Add a comment

Your email address will not be published. Required fields are marked *

  1. john Setgial

    great article but I get the errors as bolewn:

    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: securityserver.TicketGrantingService_Stub
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested
    exception is: java.lang.ClassNotFoundException: securityserver.SecurityServer_Stub

    Could you tell me how to resolve it?

    Reply
    1. admin author

      The error messages looks like your Stub class not found in the CLASSPATH, maybe you need re-compile the remote implemention on the RMI server side…

      Reply
  2. Alejandro

    I had this problem when I edited the classpath for use jdbc on linux. So I commented export CLASSPATH=blahblah from my bashrc and it works.

    Reply
  3. tebogo

    well im getting an
    Starting RMI server….
    Error:Message=RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: User
    Error:Cause-java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: User
    Error:Class-class java.rmi.ServerException

    is this also got to do with classpath?

    Reply
  4. tebogo

    im running my java on RedHat linux bash, how do i set my classpath on Linux, i gedited /etc/environment and i got a file size 0. any ideas? on windows it’s simple…

    Reply
    1. admin author

      Pls use export CLASSPATH=jars to set the classpath on Linux.

      Reply
  5. Gebru Welday

    thank you so much it works so so it must be add extends UnicastRemoteObject to the class which implement the interface methods. e.g i fix the marshaling problem of this code public class servertime implements servertimeinterface{
    public TimeServerImpl() throws Exception {
    super();

    } by public class servertime extends UnicastRemoteObject implements servertimeinterface{
    public TimeServerImpl() throws Exception {
    super();

    }

    Reply
    1. admin author

      You are right that must extend UnicastRemoteObject object.

      Reply