gpt4 book ai didi

java - 面临serialversionuid 问题

转载 作者:行者123 更新时间:2023-12-03 07:38:37 24 4
gpt4 key购买 nike

您好,我们正在生成一个桌面应用程序。在我们的项目中,我们需要使用 javax.swing.ImageIcon,如果服务器请求,我们需要发送此对象。这里的问题是,如果我们在两个环境中使用相同的 JRE,则它工作正常,如果不是,我们将得到 java.io.InvalidClassException: javax.swing.ImageIcon;本地类不兼容:流classdesc serialVersionUID = -962022720109015502,本地类serialVersionUID = 532615968316031794 是否有任何解决方案可以避免这种情况,任何建议表示赞赏。提前致谢

for this what I've done is, I just got ImageIcon.java file and removed the package by using my own package. Here I've hardcoded serialversionuid, is this recommended...?

最佳答案

Javadoc javax.swing.ImageIcon包含:

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder.

正如建议的那样,您应该尝试使用 java.beans.XMLEncoder (和 java.beans.XMLDecoder )而不是序列化。

关于java - 面临serialversionuid 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18782275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com