Applet (does not declare a static final serialVersionUID field of type long)

I just began learning Java programming. I made this one program given in the first chapter on Applets (The applet class) and it gave me this error. I tried to find a solution but couldn't.

According to the book this program should display a window but I get this error when I extend the Applet class :

"Multiple markers at this line - The serializable class AppletSkel does not declare a static final serialVersionUID field of type long - The public type AppletSkel must be defined in its own file "

Heres my code;

//An Applet Skeleton

import java.awt.*;
import java.applet.*;

/*<applet code="Appletskel" width=300 height=100>
</applet>*/

//ERROR

 public class AppletSkel extends Applet { 
        public void init(){
    }

        public void start() {

        }

        public void stop(){

        }

        public void destroy() {

        }

        public void paint(Graphics g){
        }

The first message is not an error but rather a warning. Because Applet implements the Serializable interface, it is supposed to have a unique long identifier called the serialVersionUID to follow the interface's contract. The compiler is warning you that your class does not obey this rule, but please note that this is just a warning. Your code will still compile (if no other problems) and still run (if no other problems).

One way to tell the compiler to just "shut up" and ignore the problem is to use the annotation: @SuppressWarnings("serial") just before your class declaration:

@SuppressWarnings("serial")
public class MyFoo {
   //...
}

The second compiler message is a true compilation error:

The public type AppletSkel must be defined in its own file

You need to be sure that your file name matches the class name. It should be AppletSkel.java . This must be fixed for your code to run.

链接地址: http://www.djcxy.com/p/23874.html

上一篇: 我如何检查Python脚本的语法而不执行它?

下一篇: Applet(不声明long类型的静态最终serialVersionUID字段)