• Post Reply Bookmark Topic Watch Topic
  • New Topic

CLASS PATH Help  RSS feed

 
qolokh chimto
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi every one,

I hope some one help me here I'm so frustrated after 3 hours of work but still didn't come up with any solution.
I've attached the printscreen of my code and error.

Please find the attachment and help me. I think it's the classpath issue. I've already changed it from Environment Variable from System Properties,

Looking forward to hear from ya ...

Many thanks
output.png
[Thumbnail for output.png]
java output
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Please read your private messages for an administrative issue.

Did you compile your source file before you tried to run it? You'll have to compile it first, with a command like this: javac Hello.java. That will give you a class file, named Hello.class. When you have that, you can run it with the command: java Hello.

It's advisable to not set the CLASSPATH environment variable. If it's not set, Java will look for class files in the current directory.

Try compiling and running your program from the Windows command prompt instead of from your editor directly; in the Windows command prompt you'll have more control over what the current directory is and what commands you run exactly.
 
qolokh chimto
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jesper,
and sorry I was just in a hurry trying to get rid of those lol

I did compile, while I compile i get no error but as soon as I execute i get those errors.
Nonetheless with small program " Hello world " I'm able to execute through commond prompt but simliar way i tried to execute another java code all in vain.

I had no problem executing that code at College.

What is the best way to sort it out!! do ya want some more print screen, I get exactly the same error in Commond Prompt as i attached in my first thread.

these are the following errors.


---------- Capture Output ----------
> "C:\Program Files\Java\jdk1.6.0_21\bin\java.exe" Hello
java.lang.NoClassDefFoundError: Hello
Caused by: java.lang.ClassNotFoundException: Hello
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Hello. Program will exit.
Exception in thread "main"
> Terminated with exit code 1.

THanks
Qolokh

 
subhash kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error Trace showing :

Your JVM(java tool) is unable to find the Hello.class

One way as jesper told to set the classpath and run your program from command prompt.
Second is your Crimosn editor also having some setting which will allow you to set the classpath for the jvm
most probable it will be in your Tools>>java .

main problem is jvm is looking for classes at the current directory(default behavior or jvm).
current directory means where you jvm is running.
and it is not finding you Hello.class file.
 
qolokh chimto
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kumar for the reply

Kumar can you please give some more details about CLASSPATH, How to setup ? I've already change the CLASSPATH in Environment Variable,

Under SystemVariable, I choose CLASSPATH , I changed to this " ;C:\Program Files\Java\jdk1.6.0_21\bin "
It's where I've installed java.

I tried to execute from Commond Prompt but still no difference..


Looking forward to hear from you

Thanks


 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set as classpath to C:\Program Files\Java\jdk1.6.0_21\lib\tools.jar and while your saving the program save it with double quotes because it gets attached with .txt along with .java extention save it as "Hello.java"
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
 
qolokh chimto
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No luck same error.

Thanks any way...I'm going to College tomorrow definitely ask my teacher. if he couldn't not help me I'll put some more screen shots

Thanks

Qolokh
 
qolokh chimto
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there I'm back again!!!

I went to my teacher asked him for help he was in a reall hurry so he added this lines "
"C:\Program Files\Java\jdk1.6.0_21\bin"
in PATH at the end of the those lines under System Variable.

Then he went to commond prompt and typed " Java" some help thing came up
He goes every thing is fine ya should have no problem. He goes away left me in the middle of no where . IT'S STILL NOW WORKING!!!

when i compile no errors as soon as I hit the execute button It fires all those errors. Please I need your immediate help.
I changed the CLASSPATH to " C:\Program Files\Java\jdk1.6.0_21\bin "
and I changed PATH to " %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;"C:\Program Files\Java\jdk1.6.0_21\bin"

If this is wrong please correct me ...
Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!