Search code examples
javaserializationawtserialversionuid

serialVersionUID field warning in eclipse


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!


Solution

  • 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:

    Preferences -> Java -> Compiler -> Errors/Warnings tab -> Potential programming problems section -> Serializable class without serialVersionUID -> Ignore

    To disable the warning for a single project:

    Right-click on the project -> Properties -> Java Compiler -> Errors/Warnings -> click Enable project specific settings (if necessary) -> Potential programming problems section -> Serializable class without serialVersionUID -> Ignore