views:

38

answers:

3

I have an applet I've built using NetBeans, called AKApplet. It runs fine in the IDE, but when I put it in a web page it throws the following error:

Exception in thread "Thread-15" java.lang.NoClassDefFoundError: AKApplet$2
    at AKApplet.run(AKApplet.java:675)

The applet uses the run() method to load some data in the background while keeping the UI responsive. Pretty standard stuff. At line 675, after the data has been loaded, I'm trying to update the UI components using invokeLater():

public void run() {

    // ... data loads ...

    // line 675:
    javax.swing.SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            userMessages.setText("Data loaded.");
            panelList.setVisible(true);
            validate();
            }
    });

}

The components I'm trying to update are userMessages, a JLabel and panelList which is a Panel. I don't think it's getting that far however.

Does anyone know what might be happening? At this point the applet has loaded and the components can be seen and have been updated, etc.

A: 

Are there any static definitions in the second inner class of AKApplet that could throw any kind of exception?

Exceptions in the static initializer are the most common cause for NoClassDefFoundErrors after you have made sure that the class file exists and is on the classpath.

nhnb
+1  A: 

Make sure you're deploying not only AKApplet.class, but also AKApplet$1.class, AKApplet$2.class, etc.

kschneid
+1  A: 

I guess I don't understand what the $ classes refer to. There is only a single AKApplet class, no inner classes. There are no static definitions either.

I do have two other classes defined, but they are separate classes:

class ThreadFlags { /*...*/ }

class DeleteButton extends JLabel { /*...*/ }

Also, I've verified that they are in AKApplet.jar file at the root level:

META-INF/MANIFEST.MF
META-INF/AKAPPLET.SF
META-INF/AKAPPLET.DSA
META-INF/
AKApplet.class
DeleteButton.class
ThreadFlags.class

Update: Ok, I found the AKApplet$.class files in the /build/classes/ directory of the NetBeans project. I added them, and it works. Thanks for your help. Can someone give me a brief explanantion of what those files are? As I said, there are no inner classes that I've defined...

arbingersys
Look at your compilation output, they should be there. The code: `new Runnable() {...}` will create one of them.
kschneid
Ahh. I guess I was wrong. There *were* some inner classes, the Runnable() classes. Now it all makes sense. I invoke Runnable() twice in the applet. Thanks again, excellent response.
arbingersys