Click here to Skip to main content
15,914,165 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
i have a class called Hamzah inside a package called hamzah i tried to run it from Command line but always i have NoClassDefFoundError the class compiled correctly and .class file produced but it didn't run
i try to do the following :

<br />
<C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>javac Hamzah.java>



Compiled successfully

and this for run :

C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com\hamzah>java -cp . Hamzah


Error here .
Posted
Updated 6-Jan-12 2:40am
v2

Try from the directory above and call it like:
Java
C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src\com>java hamzah.Hamzah
// or
java hamzah/Hamzah
 
Share this answer
 
Comments
hamzah1 6-Jan-12 9:42am    
This didnt works to :S
Richard MacCutchan 6-Jan-12 9:50am    
That works fine for me, so there must be something different in your setup. Please edit your question and show the source of your Java file: just the relevant parts.

Nagy Vilmos 6-Jan-12 9:59am    
Fixed [I think] see above. It's the old "launch above the package" problem.
Richard MacCutchan 6-Jan-12 11:10am    
Well spotted, I didn't think of the com. part.
If you'r in the same folder as the Hamzah.class file, you can invoke it directly using:
java Hamzah

This assumes Hamzah has a valid main method.
Assuming your class is in package com.hamzah, build and run from the src directory:

C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src>javac com\hamzah\Hamzah.java
C:\Users\h.khammash\Desktop\Studening workspace\TestCmd\src>java com.hamzah.Hamzah
 
Share this answer
 
v2
Comments
hamzah1 6-Jan-12 9:13am    
It throw the same exception and Hamzah has the main method
Nagy Vilmos 6-Jan-12 10:00am    
What is the pacgage name for your class? is it com.hamzah?
hamzah1 6-Jan-12 10:11am    
It's work now thanks alot
hamzah1 6-Jan-12 10:17am    
but can you tell me why this exception happened and why by going to src directory it run Ok. ?
thanQ.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900