Solved

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

Posted on 2004-09-06
6
270 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 115
allswap challenge 6 99
mockito example issue 8 73
Java Timer (static) 9 45
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

803 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