【问题标题】:java.io.ObjectStreamClass cannot be cast to java.lang.Stringjava.io.ObjectStreamClass 不能转换为 java.lang.String
【发布时间】:2010-08-19 10:55:01
【问题描述】:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast to java.lang.String
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at com.nxl.smssession.SessionRMI.<init>(SessionRMI.java:33)
at com.nxl.smssession.Main.main(Main.java:33)
Caused by: java.lang.ClassCastException: java.io.ObjectStreamClass cannot be cast to java.lang.String

谁能解释为什么会发生这个错误

这发生在我做 RMI 绑定操作

此问题仅在 SOLARIS 系统上发生,在 Windows 和 Linux 中运行良好

这是产生此错误的代码

public SessionRMI(String servicename) throws AlreadyBoundException {  
    SessionImpl service = new SessionImpl();   
    try {  
        logger.debug("Publishing the SMS Session endpoint " + servicename);  
        SessionIface stub = (SessionIface) UnicastRemoteObject.exportObject(service, 0);  
        Registry registry = LocateRegistry.getRegistry(); 
        registry.rebind(servicename, stub);  
        logger.debug("SMS Session endpoint published successfully "+servicename);  
    } catch (RemoteException ex) {  
        logger.error(ex.toString()); ex.printStackTrace();  
    }  
} 

提前致谢

【问题讨论】:

    标签: java casting rmi


    【解决方案1】:

    无法反序列化的是存根本身。我会仔细检查你的存根类的生成,并确保你的 Solaris 机器上没有任何旧的 .class 文件。

    【讨论】:

      【解决方案2】:

      我在 RedHat 上遇到了这个问题,我认为这可能与我启动了错误的 rmiregistry 版本有关...

      我能够通过以编程方式启动注册表来解决此问题。在registry.rebind()之前添加这个

      java.rmi.registry.LocateRegistry.createRegistry(1099);
      

      【讨论】:

        【解决方案3】:

        看起来您有一个需要String 参数的远程方法,但您却给了它一个java.io.ObjectStreamClass。这当然会引发UnmarshalException

        您应该仔细检查您的 RMI 绑定操作尝试,并确保您尝试调用正确的方法,并在需要时提供正确的参数。请查阅文档以确认 String 参数应该代表什么,并相应地提供它。

        参考文献

        【讨论】:

          【解决方案4】:

          感谢大家的帮助。

          我自己解决了这个问题。

          rmiregistry 似乎没有像在 windows 和 linux 中那样在 solaris 系统上启动。

          我必须从代​​码本身手动启动它。

          【讨论】:

          • 那会导致连接异常,而不是这个错误。
          【解决方案5】:

          没有其他信息我只能说:

          casting 尝试 Object.toString();

          ObjectStreamClass osc = new ObjectStreamClass();
          
          String str1 = (String)osc; // Throws ClasCastException
          
          String str2 = osc.toString(); // always works if osc is not null
          

          【讨论】:

            猜你喜欢
            • 2018-02-10
            • 2015-05-18
            • 2011-10-27
            • 2019-10-19
            • 2018-01-23
            • 2011-05-09
            • 2014-06-24
            • 1970-01-01
            • 2013-08-27
            相关资源
            最近更新 更多