Applet doesnt load

java.lang.NoClassDefFoundError: MainScreen (wrong name: gui/MainScreen)

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)

I have a class called MainScreen which extends JApplet and is in the package "gui"

Here is the code on my website:

<applet code = "MainScreen.class" codebase = "Interpool/gui/" width="200" height="200">

</applet>

Can you please tell me what I did wrong?

[1146 byte] By [Nethera] at [2007-11-26 13:12:37]
# 1

The code attribute of the applet tag should be "gui.MainScreen" and the codebase should probably be "Interpool".

The way you have it now, you're telling the JVM to look in the directory "gui" for a class with no package (i.e., the default package) which is a different thing from telling it to look for a class in the "gui" package.

Java uses directory structure to track things in its package structure, but they're not interchangeable. The package hierarchy isn't just a synonym for the filesystem hierarchy. This throws a lot of people at first.

Message was edited by:

paulcw

paulcwa at 2007-7-7 17:29:44 > top of Java-index,Desktop,Core GUI APIs...
# 2

I changed my code to:

<applet code = "gui.MainScreen" codebase = "Interpool" width="200" height="200">

</applet>

and got the same error

load: class gui.MainScreen not found.

java.lang.ClassNotFoundException: gui.MainScreen

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)

Caused by: java.io.IOException: open HTTP connection failed.

at sun.applet.AppletClassLoader.getBytes(Unknown Source)

at sun.applet.AppletClassLoader.access$100(Unknown Source)

at sun.applet.AppletClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

... 10 more

this time i showed more of the error

Message was edited by:

Nether

Nethera at 2007-7-7 17:29:44 > top of Java-index,Desktop,Core GUI APIs...
# 3

It looks like the same problem happened, but for a different reason.

This time, this was in the stack trace:

> Caused by: java.io.IOException: open HTTP connection failed.

Are you sure you were connected to the internet when you ran this?

Was the web server running both times? With the same configuration? Was it the same server?

Can you directly download the class file by typing the full path to it in the browser's URL window? (It will look like junk if your browser tried to display it, but we're just trying to see whether it can be accessed at all.)

It's worth noting that the first time you tried it, it did seem able to connect to the server and download the class. We know that because the class loader was able to figure out that the class that it downloaded had the wrong name. But this time apparently it can't even connect.

Message was edited by:

paulcw

paulcwa at 2007-7-7 17:29:44 > top of Java-index,Desktop,Core GUI APIs...