jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes runtime exception caused by package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "runtime exception caused by package " Watch "runtime exception caused by package " New topic

runtime exception caused by package

manoj kushwaha

Joined: Jul 12, 2005
Posts: 6
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()

file B.java.........

package b;
import a.A;
class B
public static void main(String args[])
A a=new A();

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

Joined: Oct 13, 2005
Posts: 2
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: 210

Just to revised Hein's comment, to run the command use
manoj kushwaha

Joined: Jul 12, 2005
Posts: 6
It is working
thank you very much.
I was looking for the answer for so many days nad asked so many person. thanks again
I agree. Here's the link: http://aspose.com/file-tools
subject: runtime exception caused by package
It's not a secret anymore!