Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java Exception - NoDefClassFoundError

  1. May 10, 2012 #1
    I'm trying to run a java program I coded using geany but it would let me run it as it comes up with the following error message.

    Code (Text):
    Exception in thread "main" java.lang.NoClassDefFoundError: temp
    Caused by: java.lang.ClassNotFoundException: temp
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    Could not find the main class: temp. Program will exit.
    So then I thought it may have been my bad coding but even when I copied a few example codes from wikipedia it still gave me the same error?

  2. jcsd
  3. May 10, 2012 #2


    Staff: Mentor

    It looks like you are missing a definition for a class named temp.
  4. May 10, 2012 #3


    User Avatar
    Science Advisor
    Homework Helper

    Java is different from most programming languages in that it is VERY fussy about what you call your program files, and the directory structure you put them in.

    There should be a "hello world" type of example in the system documentation. Try that, and make sure you do EXACTLY what it tells you to do.

    You might have to set up some environment variables (CLASSPATH, in particular) before anything works.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook