我有一个与serialVersionUID一行的语法错误。要解决这个错误,我必须在该行的末尾放置一个括号,并在我的代码结束时关闭它......我的问题是为什么?在包含Jframe的文件中没有必要这么做......还有什么是serialVersionUID?如果我的问题看起来很简单,我很抱歉,我对编程很陌生,对于Java更新,这是我在GUI上的第三天。为什么我的serialVersionUID后需要一个大括号?
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);
}}
序列化运行时与每个可序列化的类关联一个版本号,称为serialVersionUID,它在反序列化过程中用于验证序列化对象的发送者和接收者是否已加载该对象的与序列化相容的类。同时把你的代码放在函数中,而不是直接放在类下 – 2013-05-10 13:44:53
这不是重复的http://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it – 2013-05-10 14:24:20
@ AndyThomas克拉默我同意(我投票关闭作为“太本地化”)。如果重新打开,我会再次投票。 – 2013-05-10 14:39:25