我的理解serialVersionUID仅适用于类,因为我们只能创建一个对象,而serialVersionUID的概念是用于对象序列化和反序列化.
当我得到一个java.io.InvalidClassException时,它给了我想要的serialVersionUID,以及它得到的serialVersionUID.有没有一种简单的方法可以使用错误的serialVersionUID来判断我的几十个罐子中的哪一个?
更新:我应该提到我们的目的是同时更新所有内容,但我正在尝试在构建和部署过程中调试问题.
我最近阅读了一条评论说,从Java 5开始,不再需要使用serialVersionUID来使同一类的不同版本兼容序列化/反序列化.它是否正确?也许它与协变返回类型混淆了.所以想和大家一起来看看.
我遇到串行版本ID不匹配的问题。
我的服务器的序列号为serialVersionID = 20150301L; 和myt客户代码有所不同,因此手动进行了更改,但仍然面临相同的问题。
错误:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.io.InvalidClassException: com.fedex.supplies.j2ee.common.client.reqresp.CustomerDataRequest; local class incompatible: stream classdesc serialVersionUID = 20150901L, local class serialVersionUID = -955959537118369236.
Run Code Online (Sandbox Code Playgroud)
我尝试了像实现与服务器一样的可serializable,手动定义的serialVersionID之类的选项,但每次都得到相同的错误。
我有一个语法错误,一行与serialVersionUID.要修复此错误,我必须在该行的末尾放置一个括号,并在我的代码末尾关闭它...我的问题是为什么?在包含Jframe的文件中没有必要这个...还有什么是serialVersionUID?我很抱歉,如果我的问题看起来很简单,我是编程的新手,对Java更新,这是我在GUI上的3天.
import javax.swing.*;
public class HangmanPanel extends JPanel{
private static final long serialVersionUID = -1767262708330188227L;{
this.setLayout(null);
JLabel heading = new JLabel("Welcome to the Hangman App");
JButton Button = new JButton("Ok");
//get input
JLabel tfLable = new JLabel("Please Enter a Letter:");
JTextField text = new JTextField(10);
heading.setSize(200, 50);
tfLable.setSize(150, 50);
text.setSize(50, 30);
Button.setSize(60, 20);
heading.setLocation(300, 10);
tfLable.setLocation(50, 40);
text.setLocation(50, 80);
Button.setLocation(100, 85);
this.add(heading);
this.add(tfLable);
this.add(text);
this.add(Button);
}}
Run Code Online (Sandbox Code Playgroud)