Microsoft KB Archive/294878

= java.lang.LinkageError exception when you load an applet =

Article ID: 294878

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine

-



This article was previously published under Q294878



SYMPTOMS
When you load an HTML page that contains a Java applet, you may receive a java.lang.LinkageError exception. If the Java console is enabled in Microsoft Internet Explorer, the Java console displays output similar to the following:

Error loading class: com/myCompany/TestApplet java.lang.LinkageError: Class already defined in the context of this loader: com/myCompany/TestApplet java.lang.ClassNotFoundException: com/myCompany/TestApplet at com/ms/vm/loader/URLClassLoader.loadClass at com/ms/vm/loader/URLClassLoader.loadClass at com/ms/applet/AppletPanel.securedClassLoad at com/ms/applet/AppletPanel.processSentEvent at com/ms/applet/AppletPanel.processSentEvent at com/ms/applet/AppletPanel.run at java/lang/Thread.run



CAUSE
This exception occurs because the full Java class package name uses a forward slash (/) instead of a period (.), and the package name does not explicitly add the .class extension to the end of the Java class. For example:  



RESOLUTION
To resolve this problem, use one of the three working code class path names that are shown in the &quot;More Information&quot; section.



MORE INFORMATION
Use this simple Java applet to demonstrate the LinkageError exception, as well as to show appropriate applet full package names: package com.myCompany;

public class TestApplet extends java.applet.Applet {   public void init { this.setBackground(java.awt.Color.red); } } Place this applet code in a directory, and build it. This creates a com\myCompany subdirectory that contains the TestApplet.class file.

In the same root project directory, create the following HTML file. This code contains four  tags that attempt to load the class with various code paths:  

code=com.myCompany.TestApplet.class    

code=com.myCompany.TestApplet   </APPLET> <BR>

code=com/myCompany/TestApplet.class <BR>  </APPLET> <BR><BR>

<B>This pathname will generate the LinkageError: <BR> code=com/myCompany/TestApplet </B><BR>  </APPLET> <BR>

</BODY> </HTML> The first three examples show valid class names with the full package name specified. However, the last example generates the LinkageError exception because it uses &quot;/&quot; package delimiters and does not include the .class extension at the end of the class name.

<div class="references_section">