站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Java Tutorial 5.0 英文版

Solving Common Applet Problems - Java Tutorial 5.0 英文版

The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Deployment
Lesson: Applets

Solving Common Applet Problems

This section covers some common problems that you might encounter when writing Java applets. After each problem there is a list of possible solutions.

Problem: Applet Viewer says there's no <APPLET> tag on my HTML page, but it really is there.

  • Check whether you have a closing applet tag: </APPLET>.
Problem: I recompiled my applet, but my applet viewing application won't show the new version, even though I told it to reload it.
  • In many applet viewers (including browsers), reloading isn't reliable. This is why we recommend that you simply use the JDK Applet Viewer, invoking it anew every time you change the applet.
  • 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 Managing Source and Class Files (in the Deployment trail) for information about the CLASSPATH environment variable.
Problem: The light gray background of my applet causes the applet to flicker when it's 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. See Creating a GUI (in the Deployment trail) for details.
Problem: The Applet getImage method doesn't work.
  • Make sure 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: Now that I've copied my applet's class file onto my HTTP server, 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.
  • Did you copy all the data files for your applet -- image and sound files, for example -- to the server?
  • Make sure all the applet's class and data files can be read by everyone.
  • 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 mode) to transfer files.
Problem: I can't get my applet to run. The browser displays a ClassCastException.
  • If your applet has multiple classes, did you specify the right one (an Applet subclass) in the applet tag's CODE attribute?
Other problems that affect applets are discussed in the Creating a User Interface (AWT Only) (in the Deployment trail) trail. Specifically, look at whichever of the following sections are related to your problem: Common Component Problems (in the Deployment trail), Common Layout Problems (in the Deployment trail), Common Graphics Problems (in the Deployment trail).

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.