Hi Everyone

I want to make my code run from command prompt

I am using window 7 and JDK 6
Following are steps I did:
1) Created a Text file Example.txt. Changed the file extension to Example.java and placed it under C:\myWork
2) Open command prompt type 'dir' to see all the file in 'myWork'.
3) created a class file as Example.class from exmaple.java by javac Example.java
4) Finally on running command 'java Example'. it does work as desired as it does not print "hello world" and shows an exception "Exception in thread "main" NoClassDefFoundError: Example
Caused by: java.lang.ClassNotFoundException: Example

I dont undertsand this exception is occuring ..:(. How should i Run it successfully??? what is that i am doing wrong or missing something
Please Help!
Thanks in advance!!!!!!!!!!

Recommended Answers

All 7 Replies

check list for your problem
1. did you put any package statements in your java file?
2. are compiling and running on the same directory ?

please check those two conditions (these two are the basic cause of your problem)

Example.java contains:

class Example {
public static void main(String args[]) {
System.out.println("This is a simple Java program.");

yes I am compiling and running in same directory

Are you sure your commnad prompt says like this:

c:\>myWork>javac Example.java
c:\>myWork>java Example


yes ..:(

that's strange... I simulated your scenario to see if i was missing something... but it worked perfectly in my case as it should!

Try running any other java code in your system... btw, are you sure your jdk is valid (was downloaded from the official Oracle site)?

Thanks NP....
There was some issue in setting System Environment variables. Now this resolved

What was the exact problem? Kindly share the scenario and the solution as might help others visitng this post...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.