Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

lots of compilation error ,somebody help me with this,

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
Clyde DeSouza
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 70211
280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Disagree. EFH is correct that you needn't set a system CLASSPATH at all.
 
Clyde DeSouza
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting ClassPath once is better than setting it everytime!
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry i gget it now i have done some research i got it you were right!!!
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joywish Man wrote: my opinion others may differ



Indeed, as I've told you, the opinion of the staff differs.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classpath not proper
 
I like tacos! And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic