Two Laptop Bag*
The moose likes Beginning Java and the fly likes Installing JDK Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Installing JDK" Watch "Installing JDK" New topic
Author

Installing JDK

Joel Handloff
Greenhorn

Joined: Feb 01, 2006
Posts: 3
ok, I'm obviously not very bright...
I've installed the JDK, and I can javac my code.
when I try to run it, I get a NoClassDefFoundError.
I'm assuming that this is some sort of path issue, but wouldn't that prevent me from compiling it in the first place?
code below

public class MyFirstApp {
public static void main (String[] args) {
System.out.println("I Rule!");
}
}
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
What was the exact command that you used to interpret it? Rememember that Java is case-sensitive.

Try this

java -cp . MyFirstApp
Joel Handloff
Greenhorn

Joined: Feb 01, 2006
Posts: 3
That gets me:
Exception in thread "main" java.lang.UnsupportedClassVersionError: MyFirstApp (U
nsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Welcome to JavaRanch, and welcome to Java!

You have to make sure that you do not have the CLASSPATH environment variable set, or add "." (the current directory) to your classpath.

Read the JDK installation instructions, where setting the classpath is explained, or see the Hello World Tutorial on Sun's website, which explains what you should do if you get this error.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

java.lang.UnsupportedClassVersionError: MyFirstApp (Unsupported major.minor version 49.0)

This means that you compiled your source code with Java 1.5, but you are running it with an older version.

Make sure that you have only one version of Java installed on your computer, or make sure that the Java 1.5 binaries are found first in your PATH.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
It appears that your java refers to an older version of the JDK. This is probably because your PATH does not contain the correct bin directory. What version of the JDK did you install?
Joel Handloff
Greenhorn

Joined: Feb 01, 2006
Posts: 3
ok, yes, I probably do have two versions installed on my machine.
I don't think I can resolve that without getting in trouble here at work.
Thanks for you time!!
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Actually, you can temporarily set your PATH in your working directory so that you use the correct JDK.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Another alternative is to use the absolute path of your Java installation.
 
wood burning stoves
 
subject: Installing JDK
 
Similar Threads
Tracking Stack Trace Information
can an inner class extends the outer class?
classpath problem
Java String Question
WAS 5.1 with jre 1.4 ?