0
votes

I am new to java RMI, i was following a tutorial to learn about it. It uses a server, the code listing is as below for getting to the server

  1. CalculatorServer.java

     public class CalculatorServer {
            public CalculatorServer(){
                try {
                    Calculator c = new CalculatorImpl();
                    Naming.rebind("rmi://localhost:1099/CalculatorService", c);
                } catch (Exception e) {
                    System.out.println("Trouble"+e);
                }
            }
            public static void main(String args[]){
                new CalculatorServer();
            }
        }
    
  2. CalculatorImpl.java

     public class CalculatorImpl extends UnicastRemoteObject implements Calculator {
    
        //constructor
        public CalculatorImpl() throws RemoteException {
            super();
        }
    
        //@Override
        public long add(long a, long b) throws RemoteException {
            return a + b;
        }
    
        //@Override
        public long sub(long a, long b) throws RemoteException {
            return a - b;
        }
    
        //@Override
        public long mul(long a, long b) throws RemoteException {
            return a * b;
        }
    
       // @Override
        public long div(long a, long b) throws RemoteException {
            return a / b;
        }
    }
    

3.Calculator.java

  public interface Calculator extends Remote{
    public long add(long a, long b) throws RemoteException;
    public long sub(long a, long b) throws RemoteException;
    public long mul(long a, long b) throws RemoteException;
    public long div(long a, long b) throws RemoteException;
  }

When i debug the program, here is the error by netbeans ide console; it says this error : Troublejava.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: rmi.Calculator

1
the rmiregistry must have the interface classes on it's classpath.jtahlborn
can you post the client code please ?zguesmi

1 Answers

0
votes

It sounds like you are not running the RMI registry, which is a separate process from your CalculatorServer program. It is be located in your java bin directory. Give it a moment to start up, then try your code again.