Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Vista

 
atul vermaa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey folks. i am a beginner in Java. i have vista os.. please help me out to set class path environment. i have tried this umpteen time but coudnt make it.
one more favor i need. i have made folder name Java_Prog in D: drive and JDK is installed in C: drive. I write a program in Notepad and save it to Java_Prog folder with .java ext. and on command prompt when i try to compile my .java file then it come up with an error like "class not found exception error."
Please help me out so as i could commence coding.
Thanks a Ton in Advance.
 
Saurabh V Vakil
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by atul vermaa:
hey folks. i am a beginner in Java. i have vista os.. please help me out to set class path environment. i have tried this umpteen time but coudnt make it.
one more favor i need. i have made folder name Java_Prog in D: drive and JDK is installed in C: drive. I write a program in Notepad and save it to Java_Prog folder with .java ext. and on command prompt when i try to compile my .java file then it come up with an error like "class not found exception error."
Please help me out so as i could commence coding.
Thanks a Ton in Advance.



Before compiling the programs, enter the following :
d:\Java_Prog>set path=JDK installation directory\bin

For example if your JDK installation directory is C:\JDK1.5, then enter
set path=c:\jdk1.5\bin
then compile your program.

The only problem with this method is you have to enter the set path.... command every time you open the command prompt. So a better way is to add the classpath to the Path variable in the Environment Variables.
[ October 22, 2008: Message edited by: Saurabh Vakil ]
 
atul vermaa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Buddy. i did it as you said. now my file is compiled successfully but it is not running and giving me output.
it is showing this error: Exception in thread "main" java.lang.NoClassDefFoundEroor :Hello (Hello is my source code file name)

Thanks a Ton.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you check the directory after compilation, if the .class file exists?
 
Saurabh V Vakil
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by atul vermaa:
Thanks Buddy. i did it as you said. now my file is compiled successfully but it is not running and giving me output.
it is showing this error: Exception in thread "main" java.lang.NoClassDefFoundEroor :Hello (Hello is my source code file name)

Thanks a Ton.


After compiling the file, enter set classpath=.;
Then tr and run the file.
 
atul vermaa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Akhilesh
yes .class file exist here.

@ sourabh.
Sir i show you the whole scenario.
there are two option showing in environment variable window
1.user variable and
2.System variable
i have add variable name->path
and variable value ->(C:\Program Files\Java\jdk1.5.0_10\bin)
now
As i my folder(dir) is named as Java_prog in D: drive.
i note down java code:
class Hello
{
public static void main(String arg[])
{
System.out.println("Hello");
}
}
and file name is Hello.java saved in Java_prog in D:
now in cmd i have given command viz
D:\Java_prog>javac Hello.java
( successfully compiled)
D:\Java_prog> java Hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello
...............
now as you advised i did like this
D:\Java_prog>set path=C:\Program Files\Java\jdk1.5.0_10\bin
D:\Java_prog> java hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello
it is showing the same problem.
.....................
Thanks a Ton in advance.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by atul vermaa:
[QBnow as you advised i did like this
D:\Java_prog>set path=C:\Program Files\Java\jdk1.5.0_10\bin
D:\Java_prog> java hello
[/QB]


Before banging your head too hard, I suggest you re-read Saurabh's post. He suggested you set the classpath, not the path.
Alternatively you can try
java -cp . Hello
 
atul vermaa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i succeed
Thanks a Ton...
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by atul vermaa:
...please help me out to set class path environment. i have tried this umpteen time but coudnt make it...

If it worked with...

java -cp . Hello

...this means that you have set a system CLASSPATH that does not include a dot (.) for the current directory. You probably do not need any system CLASSPATH at all. If you added this as a new variable when installing Java, then remove it. If you must have one (if it was there before and contains other values), then it should include a dot as the first item...

CLASSPATH=.;other_stuff_if_necessary;...

Note that CLASS and CLASSPATH are entirely different things. You will find plenty of bad advice on the internet regarding CLASSPATH, which is probably why you have one set now.
[ October 22, 2008: Message edited by: marc weber ]
 
atul vermaa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that CLASS and CLASSPATH are entirely different things. You will find plenty of bad advice on the internet regarding CLASSPATH, which is probably why you have one set now.


thanks buddy.
i need one more fevor.
wht is the difference between Classpath and path variable. and how to set them while installing a fresh JDK.
Thnaks a Ton in Advance.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you have got CLASSPATH set up (it needs a . or ;. or .; or ;.; on Windows, and doesn't need anything on Linux) you never need change it.
When the java tool runs, it looks in the CLASSPATH for classes, images, etc.

The PATH ought to be set up for every installation; it tells the operating system where to find the "java" program.

Do a search through the beginner's forum; this question comes up at least once a week.
[ October 23, 2008: Message edited by: Campbell Ritchie ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic