Solved

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

Posted on 2004-09-06
6
267 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now