Common Java Applet Problems

written by: Clain Brand; article published: year 2006, month 12;


In: Root » Computers and technology » JAVA » Common Java Applet Problems

Dutch French Spanish Portuguese Italian German Japanese Chinese Korean Russian Arabic Bookmark and Share this Article

This tutorial 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 is no <APPLET> tag on my HTML page, but it really is there.
Solution: Check whether you have a closing applet tag: </APPLET>

Problem: I recompiled my applet, but my applet viewing application would not show the new version even though I told it to reload it.
Solution: In many applet viewers (including browsers), reloading is not 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.

Problem: The background color of my applet causes the applet not to match or flicker when it is drawn on a page of a different color.
Solution: You need to set the background color of the applet so that it works well with the page color.

Problem: The Applet getImage method doesn't work.
Solution: 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 is called from a constructor.

Problem: Now that I have copied my applet's class file onto my HTTP server, the applet doesn't work.
Solution:
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 appletimage and sound files, for exampleto 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: Applet is not loaded in my Web page. I see the error "java.lang.UnsupportedClassVersionError: Bad version number in .class file" in my Java Console.
Solution: T he problem is that the source for the applet is compiled with a newer version of Java than the one installed on your system. Which JRE version are you using? If it is not the latest version, make sure you install the latest Java SE Runtime Environment (JRE).

Tip for Deployers
You can compile your applets with JDK 6 using compile time options as source 1.2 and target 1.2, so that you can run them with the older versions of JRE.

Disclaimer

1) E-articles is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringement, please read the terms of service and contact us to investigate the problem.
2) E-articles is not responsible for inaccuracies, falsehoods, or any other types of misinformation this article may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here.

link to this article