Applet Problems

This section covers some common problems that you might encounter when writing applets. A list of possible solutions follows each problem.

Problem: Applet Viewer says that there's no tag on my HTML page, but it is there.

  • Check whether you have a closing applet tag:


  • Check whether you entered the correct URL for the page.

Problem: I recompiled my applet, but my browser won't show the new version, even though I told it to reload it.

  • In many browsers, reloading isn't reliable. This is why we recommend that you use the SDK Applet Viewer, invoking it anew each time you change the applet.
  • In some browsers, using Shift-Reload might reload the applet.
  • If the applet has an archive file, make sure that you updated the archive.
  • If you get an old version of the applet no matter what you do, make sure that you don't have an old copy of the applet in a directory in your CLASSPATH. See the section Path Help in Appendix E (page 540) for information.

Problem: The light gray background of my applet causes the applet to flicker when it is drawn on a page of a different color.

  • You need to set the background color of the applet so that it works well with the page color.
  • You might need to implement double buffering. See the "2D Graphics" trail in The Java Tutorial online at (Note that Swing painting is double-buffered by default.)

Problem: The applet getImage method doesn't work.

  • Make sure that you're calling getImage from the init method or a method that's called after init. The getImage method does not work when it's called from a constructor.

Problem: I've copied my applet's class file onto my HTTP server, but the applet doesn't work.

  • Does your applet define more than one class? If so, make sure that the class file (ClassName .class) for each class is on the HTTP server. Even if all the classes are defined in one source file, the compiler produces one class file per class or interface. If you use inner classes, be sure to copy their class files as well.
  • Did you copy all the data files for your appletimage and sound files, for exampleto the server?
  • Make sure that all the applet's class and data files can be read by everyone and that the directories they're in can be read and searched by everyone.
  • Make sure that the class and data files are in the correct directory, relative to the document. If you specify a code base, make sure that the class and data files are under the code base directory and that the directory name has the proper capitalization. Similarly, if your applet's classes are in a package, make sure the class files are in the right directory under the code base.


  • Make sure the applet's class and data files weren't garbled during the transfer. One common source of trouble is using the ASCII mode of FTP (rather than the binary ("BIN") mode) to transfer files. Make sure that you transfer your files in binary mode by typing bin at the command line.

Problem: When I restart my applet, it seems to show up twiceor at least the components it contains show up twice.

  • Your applet's init method is being called twice. This isn't supposed to happen, although the Applet Viewer lets you do it. One solution is to implement the applet's destroy method so that it calls removeAll, which Applet inherits from Container.

Getting Started

Object-Oriented Programming Concepts

Language Basics

Object Basics and Simple Data Objects

Classes and Inheritance

Interfaces and Packages

Handling Errors Using Exceptions

Threads: Doing Two or More Tasks at Once

I/O: Reading and Writing

User Interfaces That Swing

Appendix A. Common Problems and Their Solutions

Appendix B. Internet-Ready Applets

Appendix C. Collections

Appendix D. Deprecated Thread Methods

Appendix E. Reference

The Java Tutorial(c) A Short Course on the Basics
The Java Tutorial: A Short Course on the Basics, 4th Edition
ISBN: 0321334205
EAN: 2147483647
Year: 2002
Pages: 125 © 2008-2020.
If you may any questions please contact us: