eclipse中的serialVersionUID字段警告 [英] serialVersionUID field warning in eclipse
问题描述
我刚刚开始使用AWT并在其中制作了一个简单的程序,它工作正常,但它在eclipse中显示一条我不明白的警告信息:
可序列化类TestGUI没有声明类型为long的静态最终
serialVersionUID字段
I知道警告信息与AWT无关,并且没有必要发布我的整个代码,但当我试图制作代码的SSCCE时,警告也消失了。由于我不知道为什么会产生这个警告,所以我不知道在我的SSCCE中保留哪一部分。因此整个代码!
我的代码是:
import java .awt.Frame;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
公共类TestGUI扩展Frame {
/ **
* @param args
* /
private int x = 50;
private int y = 50;
TestGUI(String s){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
setVisible(false);
System.exit(0);
}
});
addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
x = me.getX();
y = me.getY();
repaint ();
}
});
}
public void paint(Graphics g){
g.drawString(Hello Princess,100,100);
g.drawString(鼠标点击这里,x,y);
}
public static void main(String [] args){
// TODO自动生成的方法stub
TestGUI tg = new TestGUI(first) ;
tg.setSize(500,500);
tg.setVisible(true);
}
}
提前完成Thanx!
Eclipse曾经默认禁用该警告。在Eclipse Indigo(3.7)中,默认设置是启用警告。您可以在2个位置更改设置,一个用于工作区中的所有内容,一个用于单个项目。
要禁用中所有项目的警告工作区,转到Window / Preferences并打开Java / Compiler /Errors / Warnings选项卡,打开潜在的编程问题,然后将Serializable class without serialVersionUID的值更改为Ignore(或任何你认为是合适的。)
要禁用单个项目的警告,您可以右键单击项目,选择属性,然后转到到Java Compiler /Errors / Warnings,单击Enable project specific settings(如有必要),然后选择Potential programming problems并将Serializable class without serialVersionUID的值更改为Ignore(或您认为合适的任何内容)。 / p>
I have just started on AWT and made a simple program in it, it works fine but it shows a warning message in eclipse which i don't understand:
The serializable class TestGUI does not declare a static final serialVersionUID field of type long
I know that the warning message is not related to AWT and there was no need to post my whole code but when i tried to make a SSCCE of the code the warning also disappeared. Since I don't know why this warning is generated i didn't knew which part to retain in my SSCCE. Hence the whole code!
My code is:
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestGUI extends Frame {
/**
* @param args
*/
private int x = 50;
private int y = 50;
TestGUI(String s) {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
setVisible(false);
System.exit(0);
}
});
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
x = me.getX();
y = me.getY();
repaint();
}
});
}
public void paint(Graphics g) {
g.drawString("Hello Princess", 100, 100);
g.drawString("Mouse clicked here", x, y);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
TestGUI tg = new TestGUI("first");
tg.setSize(500, 500);
tg.setVisible(true);
}
}
Thanx in advance!
Eclipse used to have that warning disabled by default. In Eclipse Indigo (3.7), the default was to enable the warning. You can change the setting in 2 places, one for everything in the workspace, and one for a single project.
To disable the warning for all projects in the workspace, go to Window / Preferences and open the Java / Compiler / "Errors/Warnings" tab, and open "Potential programming problems", then change the value of "Serializable class without serialVersionUID" to Ignore (or whatever you think is appropriate).
To disable the warning for a single project, you can right-click on the project, select Properties, then go to Java Compiler / "Errors/Warnings", click Enable project specific settings (if necessary), then select "Potential programming problems" and change the value of "Serializable class without serialVersionUID" to Ignore (or whatever you think is appropriate).
这篇关于eclipse中的serialVersionUID字段警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!