我是 java RMI 的新手,我正在按照教程来了解它。它使用服务器,获取服务器的代码清单如下
计算器服务器.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(); } }
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.计算器.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;
}
当我调试程序时,这是netbeans ide控制台的错误;它说这个错误:Troublejava.rmi.ServerException:RemoteException发生在服务器线程中;嵌套异常是:java.rmi.UnmarshalException:错误解组参数;嵌套异常是:java.lang.ClassNotFoundException: rmi.Calculator