Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package woes

 
Cathy Song
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 classes(A, B) in a package. -->lev1.lev2.lev3;

So, I created 3 directories lev1, lev2 and lev3 and placed my classes
in lev3.

package lev1.lev2.lev3;
class A {
public static void main(String[] args) {}
}

package lev1.lev2.lev3;
class B {
}

Now when I run A.class, I get the followign error:
java.lang.NoClassDefFoundError: lev1/lev2/lev3/A

Please help!!

-Cathy.
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To run a class defined in a package, the root directory must be included in your classpath. For example, if you have the following structure:
Then the root directory "projects" must be in your classpath and you need to execute the program using the fully-qualified name:
e.g. "java lev1.lev2.lev3.A"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic