Re: Exception in thread "main" java.lang.NoClassDefFoundError: sampl
On Apr 20, 6:56 am, xcrazy <sharathg...@gmail.com> 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);
}
}