1

I am using Eclipse + Window Builder + few third party libraries to build a gui application,

Entry point for my application resides in MainWindow.java file, which also contains the gui of the application, other than that I have few helper classes.

My application works fine, but when I checked into bin folder I find four more class files there namely: 1. MainWindow$1.class 2. MainWindow$2.class 3. MainWindow$3.class 4. MainWindow$4.class.

Now I don't understand why these files are here, When I deleted these files, Eclipse throws an exception

Exception in thread "main" java.lang.NoClassDefFoundError: gui/MainWindow$1
at gui.MainWindow.main(MainWindow.java:71)
    Caused by: java.lang.ClassNotFoundException: gui.MainWindow$1
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)

the code that throws the exception is:

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                MainWindow window = new MainWindow();
                window.frmMailExtractor.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

I am not able to find out why these files are there and who put them? any ideas?

OK so these are the anonymous classes, but why the Exception then?...and why can't I see them in my eclipse..becasue when I export it as a runnable jar, the jar throws the same exception

zeller
  • 4,904
  • 2
  • 22
  • 40
Sudh
  • 1,265
  • 2
  • 19
  • 30
  • 1
    They refer to anonymous inner classes. See http://stackoverflow.com/questions/380406/java-inner-class-class-file-names – Bruno Lowagie Sep 14 '12 at 10:12
  • So How would I add these in my jar..I need to run my application as a jar...When I create the jar using Eclipse's export option, It gives the same exception and closes. – Sudh Sep 14 '12 at 10:18

2 Answers2

3

These are class files generated for anonymous inner classes inside MainWindow. It probably contains a bunch of event listeners implemented as such.

Anonymous inner classes get compiled into separate class files with the name <OuterClass>$<nnn>.class, where <nnn> is a compiler-generated number.

Péter Török
  • 114,404
  • 31
  • 268
  • 329
  • So How would I add these in my jar..I need to run my application as a jar...When I create the jar using Eclipse's export option, It gives the same exception and closes. – Sudh Sep 14 '12 at 10:18
  • 1
    @Sudh, just rebuild your app to regenerate the missing class files again, the jar builder should automatically include all. – Péter Török Sep 14 '12 at 12:14
1

Those are what anonymous classes get compiled into. The number in the filename is the ordinal of the related anonymous class in the respective Java compilation unit.

Alexander Pavlov
  • 31,598
  • 5
  • 67
  • 93