This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes lots of compilation error ,somebody help me with this, Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "lots of compilation error ,somebody help me with this," Watch "lots of compilation error ,somebody help me with this," New topic
Author

lots of compilation error ,somebody help me with this,

Senthil Kumaran
Ranch Hand

Joined: Aug 24, 2008
Posts: 32
hi, am using jdk6update12, i had set classpath, path, also checked as much possibilities as i can , am getting these same errors for all programs, should i alter any in my programs or uninstall, jdk, i even tried by reinstalling it.





Exception in thread "main" java.lang.NoClassDefFoundError: hell
caused by : java.lang.ClassNotFoundException : hell
at java.net.URLClassloader$1.run<URLClassLoader.java:200>
at java.security.AccessController.doPrivileged<Native Method>
at java.net.URLClassLoader.findclass<ClassLoader.java:188>
at java.lang.ClassLoader.loadClass<Class Loader.java:307>
at sun,misc.Launcher$AppClassLoader.LoadClass<Launcher.java:301>
at java.lang.ClassLoader.LoadClass<ClassLoader.java:252>
at java.lang.Classloader.LoadClassInternal<ClassLoader.java:320>
could not find the main class:hell. program will exit.


lots of compilation error ,somebody help me with this,
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42365
    
  64
This has nothing to do with the JDK installation.

NoClassDefFoundError is not a compile error - it is a runtime error. What is the command you're trying to execute when it happens? It looks like you got the classpath wrong.


Ping & DNS - my free Android networking tools app
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
That usually indicates a classpath error, but not necessarily.

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>
Senthil Kumaran
Ranch Hand

Joined: Aug 24, 2008
Posts: 32
am getting the same errors as mentioned above, i think i have set my class path , right, somebody please help me, in which part does it goes wrong,
Clyde DeSouza
Greenhorn

Joined: Mar 16, 2009
Posts: 26
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
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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".


[Jess in Action][AskingGoodQuestions]
Clyde DeSouza
Greenhorn

Joined: Mar 16, 2009
Posts: 26
By path i forgot to mention classpath you have to set the classpath enviournment variable of your system By right clicking My computer --->properties--->Advanced---> Enviournment Variables once you set that no need for the crap like java -cp which you have to set everytime for setting the classpath. when you run your program which is quite annoying people spend usellessly more time in setting that while they could do some thing productive.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Disagree. EFH is correct that you needn't set a system CLASSPATH at all.
Clyde DeSouza
Greenhorn

Joined: Mar 16, 2009
Posts: 26
Setting ClassPath once is better than setting it everytime!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.
Clyde DeSouza
Greenhorn

Joined: Mar 16, 2009
Posts: 26
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


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!
Lucas Franceschi
Ranch Hand

Joined: Nov 10, 2008
Posts: 106

also, thats not a lot of errors, its just one error, the beautiful-multi-lines message that you see is java StackTrace.
also, dont get mad with this, its just the start for all the problems you'll face with java.



Lucas Franceschi
Software Developer for SGI Sistemas, lukas1596@gmail.com
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.
Clyde DeSouza
Greenhorn

Joined: Mar 16, 2009
Posts: 26
Sorry i gget it now i have done some research i got it you were right!!!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Joywish Man wrote: my opinion others may differ


Indeed, as I've told you, the opinion of the staff differs.
James Mathews
Greenhorn

Joined: Mar 16, 2009
Posts: 7
Classpath not proper
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: lots of compilation error ,somebody help me with this,