3 Replies Latest reply: Jun 5, 2013 7:01 PM by EJP RSS

    NoClassDefFoundError:  exception

    1012125
      I'm trying to learn java with java version "1.7.0_21". I can compile and run simple programs such as "Hello World" from the command line in Windows but when I try to use the "Swing" package I get the dreaded java.lang.NoClassDefFoundError. I get the impression that this is a path problem to find the appropriate class at run time.

      The specifics of my problem are the following:

      The program named Window.java =

      import javax.swing.*;

      class Window extends JFrame
      {
           JPanel pnl = new JPanel();
           
           public Window()
           {
                super("Swing Window");
                setSize( 500,200 );
                setDefaultCloseOperation( EXIT_ON_CLOSE );
                add(pnl);
                setVisible( true );
           }

           public static void main ( String[] args )
           {
                Window gui = new Window();
           }
      }

      The javac complier does not report any errors and the file Window.class has been created.

      When I try to run from the command line (java window) I get the following:
      ***********************************************************************************************
      Microsoft Windows XP [Version 5.1.2600]
      (C) Copyright 1985-2001 Microsoft Corp.

      C:\Documents and Settings\Brown>cd desktop\javatest

      C:\Documents and Settings\Brown\Desktop\JavaTest>java window
      Exception in thread "main" java.lang.NoClassDefFoundError: window (wrong name: W
      indow)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(Unknown Source)
      at java.security.SecureClassLoader.defineClass(Unknown Source)
      at java.net.URLClassLoader.defineClass(Unknown Source)
      at java.net.URLClassLoader.access$100(Unknown Source)
      at java.net.URLClassLoader$1.run(Unknown Source)
      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)
      at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
      *********************************************************************************************
      Can you help?