Applet runs in eclipse but not in browser

Hi, my applet runs fine in Eclipse Applet viewer. I don’t know what I did but it doesnt run in my browser any more.
When I open it it says class not found: + heaps more the same
eg:

java.lang.NoClassDefFoundError: Main$1
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(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)

I have a class called main and for some reason Eclipse is building extra class files like Main$1 and Main$2 which I don’t need and I think part of my main class is being built in them. Thats why I think its not working. But I have no idea how to fix it.
thanks for help,
roland

Those are compiled inner classes.

For example:

public class Foo {
    public class Bar {
        // Inner class. Gets compiled as Foo$1.class
    }

    public Object o = new Object() {
        // Anonymous inner class. Gets compiled as Foo$2.class
        public String toString() {
            return "overridden toString()!";
        }
    };
}

If o was inside Bar, it (or rather, its class) would get compiled as Foo$1$1.class

So you’ve got an inner class somewhere inside Main. Make sure you copy all the class files when deploying the applet.

Almost correct Markus ;D

The numbered inner classes are used only for Anonymous inner classes.
In your example you get Foo.class, Foo$Bar.class and Foo$1.class.

I was not aware of that! Thanks. =)

thanks :slight_smile:

now I found out that because I’m using ImageIO I can’t load images in my browser without signing my applet. So I tried to follow the instructions from here:

http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=149518

when it asked for a password first I tried nothing, then tried changeit because that’s what I searched for online. Here is my results.

keytool -genkey -alias RolandsJavaKey
Enter keystore password:
Keystore password is too short - must be at least 6 characters
Enter keystore password:
keytool error: java.io.IOException: Keystore was tampered with, or password was
incorrect

does anyone know what the problem is? is it the keystore or the password?

What happened to using + instead of $ for anonymous ones in 1.5? Was that ditched in 1.6? Or did it get ditched between -ea and final 1.5?

I finally figured out how to create a signed jar by creating a new key store.
I think I’m close to getting this working.