Exception in thread "main" java.lang.NoClassDefFoundError: hell
caused by : java.lang.ClassNotFoundException : hell
at java.security.AccessController.doPrivileged<Native Method>
at java.lang.ClassLoader.loadClass<Class Loader.java:307>
could not find the main class:hell. program will exit.
lots of compilation error ,somebody help me with this,
1. Make sure its set :
set CLASSPATH=.;<root dir path>;
at the CLI (if your using Windows). Then use echo %CLASSPATH% to check that its been set correctly. You can also do this by creating or editing the Environment Variable.
Set classpath in Windows XP
you should be able to compile files in sub directories from there.
2. Check to make sure your package and import statements are correct.
3. Remember that if your file resides in a sub-directory you have to run it as :
java <package>.<file name>
4. Run the java command with -cp option if your running from outside the classpath.
java -cp "<my class path>" <file name>
Joywish Man wrote:You need to restore the windows path enviournment variable google it how to do that you must have corrupted the 'path' windows enviournment variable you need to recover that ! as solution provide by Ryan did not work
Well, no. "PATH" tells Windows where to find executables like "java.exe". Since java.exe is producing this error message, it's safe to say that Windows found it.
Senthil, the best setting for CLASSPATH is nothing -- don't set it at all. The default, if there is no CLASSPATH at all, is just the current directory, which is very often exactly what you want. In any case, if you include the "-cp" switch as Ryan showed you, the CLASSPATH environment variable is ignored.
Try this. let's say that "hell.class" is in C:\WORK\JAVA. Then you type
That's "java space dash cp space period space hell".
Joywish Man wrote:Setting ClassPath once is better than setting it everytime!
That's what Ant, jar file manifests, and batch/script files are for. An environment variable is the absolute worst way to manage this sort of thing, for many of the same reasons that global variables (or public static variables in Java) are a bad idea.
That's what Ant, jar file manifests, and batch/script files are for. An environment variable is the absolute worst way to manage this sort of thing, for many of the same reasons that global variables (or public static variables in Java) are a bad idea
Everything has a purpose or else Sun Microsystem guys arent't fools to introduce global variables (or public static variables in Java) certain situations need that stuff!
Joywish Man wrote:This is a beginner forum and Simple things need to be simple for learning puposes so setting classpath is best at beginner level for trying some quick programs
This is indeed a beginner forum, and so teaching good habits is doubly important. In general, we discourage beginners from using CLASSPATH, just as we discourage them from using IDEs until they've learned to work with command-line tools.