-1

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){
        }
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Ghanendra
  • 363
  • 6
  • 15
  • If you use eclipse you can click on that warning, Quickfix and select the option 'Add generated serial version ID' - then eclipse will add a generated serial version id for you. – Lonzak Aug 27 '13 at 08:19

2 Answers2

3

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.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
0

Use this code before your @WebServlet in order to fix the problem. @SuppressWarnings("serial")

for example:

@SuppressWarnings("serial")
@WebServlet("/Servlet")
ThanhPhanLe
  • 1,315
  • 3
  • 14
  • 25