1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Exception in thread main java.lang.NoClassDefFoundError:

  1. Sep 3, 2008 #1
    Exception in thread "main" java.lang.NoClassDefFoundError:

    I was getting this error trying to compile some java programs in SSH Secure Shell. Then I made a simple "Hello World" program in my home directory to see if it would compile by typing 'java HelloWorld' but all I got was:

    Caused by: java.lang.ClassNotFoundException: HelloWorld
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

    I looked it up on google and a website said to try compiling by typing
    'java -classpath.HelloWorld' but that gave me the error:

    Unrecognized option: -classpath.HelloWorld
    Could not create the Java virtual machine.

    I haven't used Secure Shell in a long time, any help is appreciated.
  2. jcsd
  3. Sep 5, 2008 #2
    Re: Exception in thread "main" java.lang.NoClassDefFoundError:

    You have to type "javac HelloWorld.java," assuming you have your .bash_profile set up correctly. Otherwise, it's trying to run a program that doesn't exist.

    Also, make sure $HOME/.bash_profile has something like this in it:

    JAVADIR="j2re1.6.2_xx" (note you must ensure that the proper version and release number are coded here)
    export JAVADIR
    export PATH
    export CLASSPATH
  4. Sep 22, 2008 #3
    Re: Exception in thread "main" java.lang.NoClassDefFoundError:

    Try this...

    compile with this command

    javac [javafilename].java

    then after u get the classfile (the bytecode)

    run using :

    java -classpath . [javafilename]

    this will specify that the classpath is the current directory ( . ----> refers current working directory).
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Exception in thread main java.lang.NoClassDefFoundError:
  1. Exception Handling (Replies: 7)

  2. Exception in C++ (Replies: 6)