Solved

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

Posted on 2004-09-06
6
271 Views
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
ava/certification/Condit)
        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)

C:\java\certification>

Any idea what I am doing wrong?

Cheers
frankis
0
Comment
Question by:frankis
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 11992744
you need to run it with:

java certification.Condit
0
 
LVL 92

Accepted Solution

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

Expert Comment

by:skiitd
ID: 11994380
oh its a typical pkg problem

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

should work....

Thanks,
Surender
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Expert Comment

by:Naveen13
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
0
 

Author Comment

by:frankis
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?

Thanks
Frankis
0
 
LVL 92

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

830 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