RMI异常"错误编组参数"

时间:2015-09-11 16:52:31

标签: java rmi

我正在开发一个RMI项目,该项目有两个独立的Client和Server项目。我用了启动rmiregistry。当我尝试运行我的服务器应用程序时,我得到一个例外。

public class Runner extends UnicastRemoteObject {

    public Runner() throws RemoteException {
        try {
            ServerOperations so = new ServerSide();
            Naming.rebind("rmi://localhost:2000/MiveCoffeeService", so);
            System.out.println("Server is online.");

        } catch (RemoteException | MalformedURLException | FileNotFoundException ex) {
            Logger.getLogger(Runner.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void main(String[] args) throws RemoteException {
        new Runner();
    }

}

例外情况是:

Sep 11, 2015 9:05:51 PM ir.nscogroup.coffeemive.Runner <init>
SEVERE: null
java.rmi.MarshalException: error marshalling arguments; nested exception is: 
    java.io.NotSerializableException: dataaccess.ServerSide
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at java.rmi.Naming.rebind(Naming.java:177)
    at ir.nscogroup.coffeemive.Runner.<init>(Runner.java:29)
    at ir.nscogroup.coffeemive.Runner.main(Runner.java:38)
Caused by: java.io.NotSerializableException: dataaccess.ServerSide
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
    ... 4 more

有什么问题?

3 个答案:

答案 0 :(得分:5)

异常堆栈跟踪告诉你完全出了什么问题:

Force stop

您正在尝试序列化一个不可序列化的类dataaccess.ServerSide。解决方案:使您的类和所有必要的组成类实现Serializable接口。

答案 1 :(得分:3)

这里的问题是ServerSide既不是导出的远程对象也不是Serializable.几乎可以肯定你是前者,所以你必须要么:

  • 使其展开UnicastRemoteObject
  • 在绑定之前通过UnicastRemoteObject.exportObject()
  • 自行手动导出

注意不要两者兼得。

答案 2 :(得分:-1)

谢谢你们。这个样本解决了我的问题。

>> pylon_mex_camera_interface('delete', h)