Hi
I have a sorting applet that implements Bubble Sort and Insertion sort, and i have a couple of classes in my program. I made it using netbeans and i have no main class, and when i run it using this code:

<html>
<applet code=Sorter.class
        width=800 height=300>
</applet>
</html>

I get the following

java.lang.NoClassDefFoundError: Sorter (wrong name: sort2/Sorter)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: Sorter (wrong name: sort2/Sorter)

It is in a package called sort2 in netbeans, i just wondered whats going wrong.

Cheers
Paul

I think you need to add a CODE BASE parameter with a value that specifies where your .class file is located.

Without it, I don't think the AppletViewer can locate your .class file. I don't know enough about the JDK to verify this, but I do recall having a similar problem after trying to make an Applet run on a different server.

So now my file looks like this:

<html>
<applet code="Sorter"
        width="800" height="300"
        CODEBASE="C:\Documents and 

Settings\Paul\My 

Documents\NetBeansProjects\Sort2\build

\classes\Sort2\">
</applet>
</html>

But i still get this error

oad: class Sorter not found.
java.lang.ClassNotFoundException: Sorter
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\Paul\My Documents\NetBeansProjects\Sort2\build\classes\sort2\Sorter.class (The system cannot find the file specified)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(Unknown Source)
	at java.io.FileInputStream.<init>(Unknown Source)
	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
	at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	... 7 more
Exception: java.lang.ClassNotFoundException: Sorter

I am so confused right now, it works fine in the netbeans applet viewer

Try it with your code base one level higher, like this

<html>
<applet code="Sorter"
        width="800" height="300"
        [B]CODEBASE="C:\Documents and Settings\Paul\My Documents\NetBeansProjects\Sort2\build\classes">[/B]
</applet>
</html>

It looks like you had the package directory in the previous code base.

Yeah now i get this:

load: class Main not found.
java.lang.ClassNotFoundException: Main
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Documents and Settings\Paul\My Documents\NetBeansProjects\Sort2\build\classes\Main.class (The system cannot find the file specified)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(Unknown Source)
	at java.io.FileInputStream.<init>(Unknown Source)
	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
	at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	... 7 more
Exception: java.lang.ClassNotFoundException: Main

But when i put the html file in the same directory as the classes then i get this error

java.lang.NoClassDefFoundError: Main (wrong name: sort2/Main)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: Main (wrong name: sort2/Main)

Oh and by the way i renamed the class main, and refactored it so it is still all working in netbeans.

Just wondering, if no-one can solve this where should i go for help? Is there a specific java forum somewhere on the web that would be able to help me with this?

WWOOOOOO!!! Thankyou! That is perfect!

<APPLET codebase="classes" code="sort2/Main.class" width=800 height=300></APPLET>

That is the code that worked in the end. Gosh, i am so happy now. Thanks for all your help Ezzaral.

This question has already been answered. Start a new discussion instead.