java.io.ObjectStreamClass 无法转换为 java.lang.String

发布于 2024-09-14 17:11:03 字数 1488 浏览 6 评论 0原文

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.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

Can someone explain why this error is happening

This is happening when i am doing RMI Bind Operation

This problem is happening on SOLARIS System only, it is working fine in windows and Linux

Here is the code which generates this error

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();  
    }  
} 

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

深者入戏 2024-09-21 17:11:03

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

It's the stub itself that can't be deserialized. I would double-check the generation of your stub class, and make sure you don't have any old .class files lying around on the Solaris box.

我的奇迹 2024-09-21 17:11:03

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

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

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

I had this problem on RedHat, i think it might have been to do with me starting the wrong rmiregistry version ...

I was able to solve this issue by starting the registry programmatically. Add this before registry.rebind()

java.rmi.registry.LocateRegistry.createRegistry(1099);
人海汹涌 2024-09-21 17:11:03

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

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

参考文献

It looks like you have a remote method that expects a String argument, but instead you give it a java.io.ObjectStreamClass instead. This will of course raise an UnmarshalException.

You should carefully examine your RMI bind operation attempt and ensure that you are trying to invoke the right method, and you're providing the right arguments wherever needed. Consult the documentation to confirm what the String argument is supposed to represent, and provide it accordingly.

References

入怼 2024-09-21 17:11:03

谢谢你们的帮助。

我自己解决了这个问题。

看起来 rmiregistry 在 Solaris 系统上没有像在 Windows 和 Linux 中那样启动。

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

Thanks for the help guys.

I solved the problem myself.

It seems like the rmiregistry was not starting up on the solaris system as it does in windows and linux.

I had to manually start it from within the code itself.

回眸一笑 2024-09-21 17:11:03

没有额外的信息我只能说:

代替铸造尝试Object.toString();

ObjectStreamClass osc = new ObjectStreamClass();

String str1 = (String)osc; // Throws ClasCastException

String str2 = osc.toString(); // always works if osc is not null

Without additional info i can only say:

Intead of casting try Object.toString();

ObjectStreamClass osc = new ObjectStreamClass();

String str1 = (String)osc; // Throws ClasCastException

String str2 = osc.toString(); // always works if osc is not null
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文