did you compile the class (running the java compiler using javac or in your IDE) ? is the class file on the classpath ?
because the error message just means that the class you want to run can not be found on the classpath.
the classpath is something like a collection of classes (.class files, but also class files in jar files) and resources (e.g. images you can load without using system specific/absolute file paths). you specify it using the -cp or -classpath option.
e.g. java -cp .;somedir/classes;somejar.jar MyApp
for simple programs (consisting of just the classes, no libraries that are used) it is usualy enough to change to the directory where the class files reside (root of your package structure).
Welcome to the world of Java.. :-) Hey Bert , A new Novice Added to our Ranch..
Steve , What you can try to figure out is , Have you set the neccesary things to run your first app.. I mean Have you defined the path for your application ? Path variable is very important. What i would suggest you is this.
1)Add path variable to your environmental variables of your machine , If you dont know where they are , Here's it. Point ur mouse to My Computer -> Right Click -> Properties-> Goto Advanced Tab-> Environmental Variables.
2)Click on New under "User Variables" and give the name of the variable as path and value as the Address of the place where you installed j2sdk. For instance , I have it on my c: , So example can be variable name=path, variable value=c:\j2sdk1.4.0\bin, AFter setting this , Save your program in c:\j2sdk1.4.0\bin and then try to run your app again.. i.e save it as c:\j2sdk1.4.0\bin\MyFirstApp.
Have a great day ! Yogendra.
Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Joined: Apr 14, 2006
I had the PATH EnVar set to the BIN directory. I had no problems compiling.
I'm confused with teh class settings. I did the typical install of JDK 1.5. The CLASSPATH is set to as follows:
that tells java to use the current directory as (part of?) the classpath.
this is a short term solution, but it might at least let you get the code to run.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Apr 14, 2006
Thanks, Fred. I tried it and received the following:
C>java -cp . MyFirstApp Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstApp (Unsupported major.minor version 49.0) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Maybe I should have stuck with .Net (Just kidding!)