This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi! I have created two packages a and b and placed two classes A and B in them respectably. Class files are as follows
file A.java.........
package a; public class A { public void hello() { System.out.println("hello"); } }
file B.java.........
package b; import a.A; class B { public static void main(String args[]) { A a=new A(); a.hello(); } }
above program is compiling without any error but when i am trying to run it, its giving following Exception
Exception in thread "main" java.lang.NoClassDefFoundError: B (wrong name: b/B) at java.lang.ClassLoader.defineClass0(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.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 java.lang.ClassLoader.loadClassInternal(Unknown Source)
I have checked my classpath variable also but not getting the root of problem. please help me out....
Hein Behrens
Greenhorn
Joined: Oct 13, 2005
Posts: 2
posted
0
I put the files in a and b directory. Go to the directory above a and b. javac a/A.java javac b/B.java java b.B works prints hello.
Do not run B from within the B directory or compile from within the directory. [ October 14, 2005: Message edited by: Hein Behrens ]
Wirianto Djunaidi
Ranch Hand
Joined: Mar 20, 2001
Posts: 195
posted
0
Just to revised Hein's comment, to run the command use
manoj kushwaha
Greenhorn
Joined: Jul 12, 2005
Posts: 6
posted
0
It is working thank you very much. I was looking for the answer for so many days nad asked so many person. thanks again