Packages:Exception in thread "main" java.lang.NoClassDefFoundError

Posted on 2004-09-06
Medium Priority
Last Modified: 2010-03-31
I have a class, Condit, which compiles and runs fine, when it is in the default package, but when I set it to be in package certification;
It compiles but when I try to run it this error comes up:
C:\java\certification>java Condit
Exception in thread "main" java.lang.NoClassDefFoundError: Condit (wrong name: j
        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)


Any idea what I am doing wrong?

Question by:frankis
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 92

Expert Comment

ID: 11992744
you need to run it with:

java certification.Condit
LVL 92

Accepted Solution

objects earned 200 total points
ID: 11992748
you'll also need to add c:\java to your classpath if it is not there already.

Expert Comment

ID: 11994380
oh its a typical pkg problem

after compiling try
C:\java\java certification.condit

should work....

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Expert Comment

ID: 11994469

Hello Frankis..

 The problem may be for the following reasons

1)   Get one step back form your current directory then it looks like "c:\java"  here use  
java certification.condit

Author Comment

ID: 12000148
Thanks Objects, that seems to have done the trick, but I always thought that if you have a period in the classpath:
classpath=.;C:\certified etc

the class would run. How come it worked when it was default package?

LVL 92

Expert Comment

ID: 12001361
. (current directory) would work if you ran it from c:\java
add c:\java explicitly allows you to run from any directory

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question