Exception in thread "main" java.lang.NoClassDefFoundError: sampl

Discussion in 'Java' started by xcrazy, Apr 20, 2007.

  1. xcrazy

    xcrazy Guest

    Hi, I know this is a common error, but this occurs only in some of my
    programs.
    I run java on windows XP SP2, jdk1.5
    My sampl.java file is like this:

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    class swing_app {
    public static void main(String[] args) {
    JDesktopPane desktop = new JDesktopPane();
    desktop.add(desktop,BorderLayout.CENTER);
    JInternalFrame internalFrame = new JInternalFrame("Internal
    Frame",true,true,true,true);
    internalFrame.setBounds(50,50,200,100);
    desktop.add(internalFrame,new Integer(1));
    }
    }

    It compiles giving me a "sampl.class" file but when i type this
    >java sampl

    I get this error: - Exception in thread "main"
    java.lang.NoClassDefFoundError: sampl

    I don't get this error in a simple "Hello world" program.....
    This is how i've set my paths:

    Path=c:\j2sdkee1.3.1\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot
    %\system32\WBEM;%SYSTEMROOT%\system32\WBEMC:
    \PROGRA~1\COMMON~1\AUTODE~1;.;C:\Java\jdk1.5.0_09\bin;c:\Java
    \jdk1.5.0_09\lib;

    CLASSPATH= .;C:\Java\jdk1.5.0_09\lib;C:\Java\jdk1.5.0_09\bin;C:
    \j2sdkee1.3.1\bin;

    Please help!!
     
    xcrazy, Apr 20, 2007
    #1
    1. Advertising

  2. On Apr 20, 1:56 pm, xcrazy <> wrote:
    > Hi, I know this is a common error, ..


    Multi-posting instead of cross-posting?
    Please refrain from multi-posting, in future.
    <http://www.physci.org/codes/javafaq.html#xpost>

    Andrew T.
     
    Andrew Thompson, Apr 20, 2007
    #2
    1. Advertising

  3. xcrazy

    micro Guest

    On Apr 20, 6:56 am, xcrazy <> wrote:
    > Hi, I know this is a common error, but this occurs only in some of my
    > programs.
    > I run java on windows XP SP2, jdk1.5
    > My sampl.java file is like this:
    >
    > import java.awt.*;
    > import java.awt.event.*;
    > import javax.swing.*;
    >
    > class swing_app {
    > public static void main(String[] args) {
    > JDesktopPane desktop = new JDesktopPane();
    > desktop.add(desktop,BorderLayout.CENTER);
    > JInternalFrame internalFrame = new JInternalFrame("Internal
    > Frame",true,true,true,true);
    > internalFrame.setBounds(50,50,200,100);
    > desktop.add(internalFrame,new Integer(1));
    > }
    >
    > }
    >
    > It compiles giving me a "sampl.class" file but when i type this>java sampl
    >
    > I get this error: - Exception in thread "main"
    > java.lang.NoClassDefFoundError: sampl
    >


    first :note that your class named "swing_app" not "sampl" it wil
    compile giving you a "swing_app.class"
    second :you should not add acontainer to it self

    > desktop.add(desktop,BorderLayout.CENTER);

    third you are using an internal frame so you should note that you will
    not be able to see any thing unless you put that in a desktoppane then
    in a frame
    so try the following it will work:
    import javax.swing.*;

    class SwingApp {
    public static void main(String[] args) {
    JFrame f= new JFrame();
    f.setSize(300, 300);
    JDesktopPane desktop = new JDesktopPane();
    f.setContentPane(desktop);
    JInternalFrame internalFrame = new
    JInternalFrame("internal frame");
    internalFrame.setBounds(50,50,200,100);
    internalFrame.setVisible(true);
    desktop.add(internalFrame,null);
    f.setVisible(true);
    }

    }
     
    micro, Apr 20, 2007
    #3
  4. xcrazy

    micro Guest

    On Apr 20, 6:56 am, xcrazy <> wrote:
    > Hi, I know this is a common error, but this occurs only in some of my
    > programs.
    > I run java on windows XP SP2, jdk1.5
    > My sampl.java file is like this:
    >
    > import java.awt.*;
    > import java.awt.event.*;
    > import javax.swing.*;
    >
    > class swing_app {
    > public static void main(String[] args) {
    > JDesktopPane desktop = new JDesktopPane();
    > desktop.add(desktop,BorderLayout.CENTER);
    > JInternalFrame internalFrame = new JInternalFrame("Internal
    > Frame",true,true,true,true);
    > internalFrame.setBounds(50,50,200,100);
    > desktop.add(internalFrame,new Integer(1));
    > }
    >
    > }
    >
    > It compiles giving me a "sampl.class" file but when i type this>java sampl
    >
    > I get this error: - Exception in thread "main"
    > java.lang.NoClassDefFoundError: sampl
    >


    first :note that your class named "swing_app" not "sampl" it wil
    compile giving you a "swing_app.class"
    second :you should not add acontainer to it self

    > desktop.add(desktop,BorderLayout.CENTER);

    third you are using an internal frame so you should note that you will
    not be able to see any thing unless you put that in a desktoppane then
    in a frame
    so try the following it will work:
    import javax.swing.*;

    class SwingApp {
    public static void main(String[] args) {
    JFrame f= new JFrame();
    f.setSize(300, 300);
    JDesktopPane desktop = new JDesktopPane();
    f.setContentPane(desktop);
    JInternalFrame internalFrame = new
    JInternalFrame("internal frame");
    internalFrame.setBounds(50,50,200,100);
    internalFrame.setVisible(true);
    desktop.add(internalFrame,null);
    f.setVisible(true);
    }

    }
     
    micro, Apr 20, 2007
    #4
  5. xcrazy

    Lew Guest

    xcrazy <> wrote:
    >> Hi, I know this is a common error, but this occurs only in some of my
    >> programs.
    >> I run java on windows XP SP2, jdk1.5
    >> My sampl.java file is like this:
    >>
    >> import java.awt.*;
    >> import java.awt.event.*;
    >> import javax.swing.*;
    >>
    >> class swing_app {


    Class names should start with an upper-case letter, not contain underscores
    and start each word part with an upper-case letter, thus "SwingApp", by
    convention.

    --
    Lew
     
    Lew, Apr 20, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page