Hi all, im trying to run so many codes using java RMI and nothing seems to work. im on the point of banging my head on the PC.
Im sure evryone is aware of the popular Calculator example: Calcuator.java, CalcuatorImpl.java, CalcuatorClient.java and CalcuatorServer.java. I hae done this and other examples at University and they executed and compiled all fine but when I run them on my own PC, I get the following error. could some one help me please.

java.rmi.ServerException: RemoteException occurred in server thread;
nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments;
nested exception is:
java.lang.classNotFoundException: Calculator

HI,
I have the same problem. getting this error:

xception in FibonacciImpl.main: 
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
	java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
	java.lang.ClassNotFoundException: com.ora.rmibook.gui.FibonacciImpl_Stub

*I am using Jbuilder 2005 to create this app.
*the stubs and the skel classes have been
created and i believe they are in right folder.
*started rmiregistry but after compiling the
main class i get this above error!.

I went through all the sources online but they keep saying that you need to add your stub in your rmi registry classpath!! .. how do i add tat ?
all i know i can start rmiregistry from command prompt. but i dont know how to tell rmi where to locate the stubs. although they are in the same folder.
I also copied all my project files to a temp folder in D drive but same error. i did tat cuz i read somewhere that tomcat server gives error when there are spaces in the folder files. but tat didnt work either. HELP. thanks
please help and advice..need to learn this badly.
if u have any questions , lemme know.
thanks.

Your Remote object must Extend UnicasRemoteObject Class directly or indirectly.
UnicastRemoteObject does the marshalling and unmarshalling i.e converting arguements and return values to bytes that can be sent over the network.

taking the example of the calculator program:

Calculator would be the interface which extends Remote then your remote objects would be defined by the class CalculatorImpl.

CalculatorImpl should extend UnicastRemoteObject directly i.e

public class CalculatorImpl extends UnicastRemoteObject

or indirectly by extending a class which already inherits from UnicastRemoteObject

that will deal with the UnmarshalException

For the ClassNotFoundException Make sure you have all the classes and stubs in the right directories

import java.rmi.*;
import java.rmi.server.*;
import java.net.*;

public class server 
{
public static void main(String args[])throws Exception
{
if (System.getSecurityManager() == null)
            System.setSecurityManager ( new RMISecurityManager() );
try
{
sampleserverimpl server = new sampleserverimpl();
Naming.rebind(

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Attachments
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;

public class client
{
public static String s;
public static void main(String args[])throws Exception
{
sampleserver remoteobject  =(sampleserver)Naming.lookup("rmi://localhost/SERVER");
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader    br = new BufferedReader(is);

System.out.println("ENTER THE FIRST NUMBER:");
int a = Integer.parseInt(br.readLine());
System.out.println("ENTER THE SECOND NUMBER:");
int b = Integer.parseInt(br.readLine());
do{

System.out.println("*****ENTER YOUR CHOICE*****");
System.out.println("1.ADDITION");
System.out.println("2.SUBTRACTION");
System.out.println("3.MULTIPLICATION");
System.out.println("4.DIVISION");

int c = Integer.parseInt(br.readLine());

switch(c){

case 1   :int ans1 = remoteobject.add(a,b);
          System.out.println("THE REQUIRED ANSWER IS:"+ans1);
          break;
case 2   :int ans2 = remoteobject.sub(a,b);
          System.out.println("THE REQUIRED ANSWER IS:"+ans2);
          break;
case 3   :int ans3 = remoteobject.mul(a,b);
          System.out.println("THE REQUIRED ANSWER IS:"+ans3);
          break;
case 4   :int ans4 = remoteobject.div(a,b);
          System.out.println("THE REQUIRED ANSWER IS:"+ans4);
          break;

}
System.out.println("DO YOU WANT TO CONTINUE?Y/N");
s = br.readLine();
}
while(s.equals("y")||s.equals("Y"));
}
}
import java.rmi.*;

public interface sampleserver extends Remote
{

public int add(int a,int b) throws RemoteException;
public int sub(int a,int b) throws RemoteException;
public int mul(int a,int b) throws RemoteException;
public int div(int a,int b) throws RemoteException;

}
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;

public class sampleserverimpl extends UnicastRemoteObject implements sampleserver
{
sampleserverimpl() throws RemoteException
{
super();
}
public int add(int a,int b) throws RemoteException
{
return(a+b);
}
public int sub(int a,int b) throws RemoteException
{
return(a-b);
}
public int mul(int a,int b) throws RemoteException
{
return(a*b);
}
public int div(int a,int b) throws RemoteException
{
return(a/b);
}
};

check the port number in the Naming. rebind.....

default port for rmi is 1099 if you want to use different port you have to do

start rmiregistry <portnumber>

This article has been dead for over six months. Start a new discussion instead.