Exception in thread "main" java.lang.NoClassDefFoundError

Hi,

I am using Windows XP Service pack 2. with jdk j2sdk1.4.1_01.

I was able to compile the LeakExample.java. I have set the classpath every thing. When i Execute LeakExample using java LeakExample Iam able to see the output.

The above steps works if there is no package declared. I have created the directories according to the package specified in the code.

When i declare Packages It throws the below error

Exception in thread "main" java.lang.NoClassDefFoundError: LeakExample (wrong na

me: demos/memorydebugger/leakexample/LeakExample)

at java.lang.ClassLoader.defineClass0(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:502)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12

3)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)

at java.net.URLClassLoader.access$100(URLClassLoader.java:54)

at java.net.URLClassLoader$1.run(URLClassLoader.java:193)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:186)

at java.lang.ClassLoader.loadClass(ClassLoader.java:299)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)

at java.lang.ClassLoader.loadClass(ClassLoader.java:255)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)

The source code i am testing is below.

package demos.memorydebugger.leakexample;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class LeakExample extends JFrame {

JPanel panel = new JPanel();

JButton buttons[] = new JButton[100];

int numButtons = 0;

static boolean fixed = false;

public LeakExample() {

super("Leak Example");

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e){

System.exit(0);

}

});

panel.setLayout(new FlowLayout() );

getContentPane().add("Center", panel);

JPanel addRemovePanel = new JPanel();

JButton addBtn = new JButton("Add");

addBtn.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

addButtonToPanel();

}

});

addRemovePanel.add(addBtn);

JButton removeBtn = new JButton("Remove");

removeBtn.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

removeButtonFromPanel();

}

});

addRemovePanel.add(removeBtn);

getContentPane().add("North", addRemovePanel);

}

public void addButtonToPanel() {

if ( numButtons < buttons.length ) {

JButton btn = new JButton(String.valueOf( numButtons ) );

buttons[numButtons++] = btn;

panel.add(btn);

panel.validate();

panel.repaint();

}

}

public void removeButtonFromPanel() {

if ( numButtons > 0 ) {

panel.remove(buttons[--numButtons]);

if(fixed) {

buttons[numButtons] = null;

}

panel.validate();

panel.repaint();

System.gc();

}

}

static public void main(String args[]) {

if (args.length > 0) {

if (args[0].equals("fix")) {

fixed = true;

}

}

JFrame frame = new LeakExample();

frame.setSize(300, 200);

frame.setVisible(true);

}

} // End of class

Please let me know where iam going wrong.

Regards,

manju

[3509 byte] By [manjunathvenkatesha] at [2007-10-2 22:27:26]
# 1
I got the answer.You need to compile from outside the demos folder. ex:c:/java demos.memorydebugger.leakexample.LeakExample.This solved my problemmanju
manjunathvenkatesha at 2007-7-14 1:45:00 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...