java.lang.NoClassDefFoundError: (wrong name)
800442May 7 2007 — edited Oct 15 2007Hi,
I know this has been discussed a million times before, but I have read through various threads in the forum and tried the suggested solutions, but I still can't run my java applet. I use NetBeans 5.5. Under "Project properties/Run", Main Class path is set to "lottoapplet.LottoAppletUI"
Beginning of my code looks like this:
package lottoapplet;
import java.math.*;
import javax.swing.JLabel;
import javax.swing.*;
import java.text.*;
public class LottoAppletUI extends javax.swing.JFrame {
...
If I build the project and try to run the applet in a browser with the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<applet code="LottoAppletUI.class" width="641" height="431">
</applet>
</body>
</html>
I get a gray box and an "X" and the java console says the (in)famous:
java.lang.NoClassDefFoundError: LottoAppletUI (wrong name: lottoapplet/LottoAppletUI)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
If I use the command prompt, the compile works fine with the -cp parameter but applet won't run:
C:\Documents and Settings\masaxp>javac -cp "C:\Documents and Settings\masaxp\My
Documents\Java projects\LottoApplet\src\lottoapplet" "C:\Documents and Settings\
masaxp\My Documents\Java projects\LottoApplet\src\lottoapplet\LottoAppletUI.java
"
C:\Documents and Settings\masaxp>"C:\Program Files\Java\jdk1.6.0_01\bin\java.exe
" "C:\Documents and Settings\masaxp\My Documents\Java projects\LottoApplet\src\l
ottoapplet\LottoAppletUI"
Exception in thread "main" java.lang.NoClassDefFoundError: C:\Documents and Sett
ings\masaxp\My Documents\Java projects\LottoApplet\src\lottoapplet\LottoAppletUI
I can run the project in the NetBeans IDE without a problem. Anyone that can decipher this and see the problem? Thanks anyway.