File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

runtime exception caused by package

 
manoj kushwaha
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 210
Ruby Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to revised Hein's comment, to run the command use
 
manoj kushwaha
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic