Java: Exception in thread main java.lang.NoClassDefFoundError

This tutorial explains a common error that beginning Java authors may experience.

    Exception in thread “main” java.lang.NoClassDefFoundError:

    When trying to run a Java program, you may get this annoying error. I first got it when running our simple hello world program.

    The error occurs because the classpath is not set up or referenced correctly.

    Executing your program using the following command should correct the problem:
    java -classpath . helloworld

    In this command, helloworld is the name of your compiled class.

    This tells Java that your classpath is your local directory.

 

About David Kirk

David Kirk is one of the original founders of tech-recipes and is currently serving as editor-in-chief. Not only has he been crafting tutorials for over ten years, but in his other life he also enjoys taking care of critically ill patients as an ICU physician.
View more articles by David Kirk

The Conversation

Follow the reactions below and share your own thoughts.

  • LP

    Very helpful! I was stuck on this.. Thanks

    • java biginer

      still get the same error .not helping .

      • vijay

        If you are using any packages in your program like

        package ABC; (lets assume ABC is in folder D:)

        class HelloWorld{

        //rest of the code goes here

        make sure to move one folder up the hierarchy and use the following command

        >D: java ABC.HelloWorld

        • arre

          > Thanks for this comment

    • Nikolai

      i was using NetBeans IDE 7.1.2… there are two icons: “+page” & ” +folder” graphical icons… i clicked on “+folder” icon (for New Project) and the template created a line:

      package helloworld; //AND it automatically compiles the .java into a .class when saving or running code.

      So… the command line “java -classpath . HelloWorld” //wouldn’t work for me.

      if you’re in a similar situation, i would try

      “java -classpath . [packagename].[ClassName]” // helloworld.HelloWorld (no .class extention)

  • Mimi

    My Classpath looks right, but I still get the error: Exception in thread “main”

    .;C:Program FilesJavajdk1.6.0_01lib

    • Rajesh

      the classpath should include the directory in which u r keeping ur own class files.

    • Sumsin123

      by default CLASSPATH is always current directory. Setting up CLASSPATH variable explicetely overrides this value

    • Deathdragon6

      no lib C:Program filesjavajdk1.6.xxxxxbin

    • C Bala86

      I got this error in my eclipse. I found there was class file getting generated for the project. Reason was no default java builder defined for the project.Opened the .project file and added the default java builder definition. Now it works fine

      • C Bala86

        Sorry class file was not getting generated previously

      • Jody

        that’s very useful!

      • Jody

        great >

  • Andy

    I’m sorry it did not work.

    • chandu

      if u have stored ur classes in the directory other than JDK installed…we need to set path to the bin dir by using
      set path=…..
      and for classes
      set classpath=….

      • Amruta

        Thank you!! It really helped me.
        i just copied my files in bin dir. try doing this.

      • harpreet

        thank you it really helped me

      • Pranav

        yp it helped me too

      • Anonymous

        Hey chandu thanks a lot it worked out for my final yr project thanks a lot once again :-)

  • CP

    I have the same issue Exception in thread “main” java.lang.NoClassDefFoundError: any luck

    • v

      Just call this at the directory where you classfile XYZ.class is located :

      java -classpath . XYZ

      • karep

        salam

        didn’t work for me …
        any idea ?? :’(

        wassalam

        • Nick

          I had a problem with that, and then I noticed, that I had written”java -classpath . XYZ.class” instead of “java -classpath . XYZ” Don’t know, if this helps you, but worked for me :)

          • Somedude

            Thanks Nick, I feel silly….

          • husy

            hmm

        • Rajroy 002

          sep path

          • Popujari

            setting path till again give same error no class deffound

      • Anonymous

        hey bro’s thnx it solved my issue

      • Nk3527

        i have found error “Exception in thread “main” java.lang.NoClassDefFoundError” when i was tring to execute my own packages.What is solution

  • springrider

    Thanks a lot! It help me!

    • abhishek

      Microsoft Windows [Version 6.0.6001]
      Copyright (c) 2006 Microsoft Corporation. All rights reserved.

      C:Usersmdube>cd

      C:>javac C:abhishekMohit.java

      C:>java C:abhishekmohit
      Exception in thread “main” java.lang.NoClassDefFoundError: C:abhishekmohit

      C:>java C:abhishek/mohit
      Exception in thread “main” java.lang.NoClassDefFoundError: C:abhishek/mohit

      C:>javac C:abhishek/Mohit.java

      C:>$Recycle.Bin
      ‘$Recycle.Bin’ is not recognized as an internal or external command,
      operable program or batch file.

      C:>JAVAC
      Usage: javac
      where possible options include:
      -g Generate all debugging info
      -g:none Generate no debugging info
      -g:{lines,vars,source} Generate only some debugging info
      -nowarn Generate no warnings
      -verbose Output messages about what the compiler is doing
      -deprecation Output source locations where deprecated APIs are us
      ed
      -classpath Specify where to find user class files
      -sourcepath Specify where to find input source files
      -bootclasspath Override location of bootstrap class files
      -extdirs Override location of installed extensions
      -d Specify where to place generated class files
      -encoding Specify character encoding used by source files
      -source Provide source compatibility with specified release
      -target Generate class files for specific VM version
      -help Print a synopsis of standard options

      C:>JAAVA

  • Tzell

    I am using JGrasp as a new Java learner and I hate it. The errors given when compiled to vague. Can anyone suggest a better application to begin learning and developing in?

    • FrederikNS

      the errors are thrown by the Sun Java Compiler, and that doesn’t differ regardless of which developer environment you try to program in, as long as it’s java, you’ll have to stick with it.
      But some of the best environment to program java in would have to be Eclipse or NetBeans.
      They have an awful lot of features, and is very easy to use when you get over the initial general troubles, such as which features to use, and getting an overview of all the stuff they can do.

      • asif

        Yes it worked in eclipse!! thanks.

    • stacy

      try netbeans

  • ahmad aghajani

    My Classpath looks right, but I still get the error: Exception in thread “main”

    .;C:Program FilesJavajdk1.5.0_01lib

  • Jim Thomas

    The above comment did not work. For newbies it may be easier to save the source files in the bin directory eliminating any path issues.

  • chandu

    we need to set two paths
    1. for JDK use following command
    set path=C:……
    2. for classes where u compiled and kept
    set classpath=D:prgrams……

  • grace

    you say executing your program using … pls how exactly do i execute it. i need the basic steps

  • Sushil Karane

    java page we get the error as follows :

    Exception in thread “main” java.lang.UnsupportOperationException at sun.jdbc.odbc.jdbcOdbcConnection.createStatement(Unknown Source)
    at DBConn.
    at ReceiveMail.
    at insertion.main(insertion.java:10)

    • http://ACompetitorsChallenge.com JAaronAnderson.com

      For my CLASSPATH I have :
      C:Program FilesJavajdk1.6.0_10jrelib;C:Program FilesJavajdk1.6.0_10jrebin;C:novellndkndssdkjavalibldap.jar;.;C:JavaProjectsSearchLDAPTest
      Where C:JavaProjectsSearchLDAPTest is where my List.class compiled class resides

      I also created JAVA_HOME Variable for my user with a value of:
      C:Program FilesJavajdk1.6.0_10

      and finally I have for my Path:
      C:Program FilesJavajdk1.6.0_10jrebin;D:Program FilesSSH Communications SecuritySSH Secure Shell;C:Program FilesJavajdk1.6.0_10binjavac.exe;C:novellndknjclv2rsrcnjcl

      Which C:Program FilesJavajdk1.6.0_10jrebin is the bin of the RUNTIME or should I also list C:Program FilesJavajdk1.6.0_10bin :: the JDK bin/ instead ?
      anyone with any CLEAR ideas ? thx

      • Abhhilash

        I have created the hello world program and i am using textpad to do that
        My program is compiling but when i run it gives me an error
        java.lang.NoClassDefFoundError:
        Exception in thread “main”
        Tool completed with exit code 1
        I have set my path to C:jdk1.3bin
        and the classpath to where the program reside but in vein can anybody help

    • irene

      noooooo…. i have tried it all…. :(
      it keeps saying that java.lang.noclassdeffounderror thing…

  • Nathiya S

    how do create path to j2sdk1.4.2_02
    i run small prgm, my error is
    exception in thread “main” java.lang.noclassdefFoundError

    how do clear my error

    • Martin

      I had the same problem. It turned out the cause was that I tried to compile a java sample file from a read-only folder.
      When I copied the .java file to my hard drive the problem went away

  • Rakesh

    Thanks great info

  • bothanks

    omfg ahmad aghajani ,
    i o u big!!!

    ty for suggesting at putting that in the Class path file, a program of mine has been corrupted for over 2 yrs, and i tried to fix it 1 last time, and ur suggestion worked!!

    ty!!

  • Amruta

    if After setting the path also it doesnt work.. save all files in bin dir and run the prgram using that path.

    • Neicey

      Here is how i fixed mine.
      The .Java and the .Class file is located in C:Java . i got the above error and changed directory at the dos prompt by typing
      cd Java (Enter)
      Then I compiled by typing the below
      C:Java>”C:Program FilesJavajdk1.5.0_16binjavac.exe” C:javasaluton.java

      Than I run by typing the below
      C:Java>java Saluton
      Results …

      Saluton Mundo!

      Hope this Helps . Arichards

    • Anonymous

      is it a problem of program?.

  • Sham

    Thanx a lot very usefull!!

  • sad

    After doing the following….where m is my class name

    java -classpath . m
    i get this……..

    Unrecognized option: -classpath.m
    Could not create the Java virtual machine.
    help is appreciated!!!1

    • techno

      i think you are not giving space between the classpath n dot n m…
      like java -classpath[space].[space]m

      mine was also having the same error but when i gave spacing between them it worked,,..so u can also try dis once…

      • desperado

        thanks techno, great advice!

      • Su

        Your advice point out what I missed. Thz alot techno.

  • The One

    Ha! I figured it out! I just wasn’t compiling every file! “javac *.java” fixed it all! YES!!

    • Anonymous

      Awesome dude thanks this solved my problem..I used to think that java.exe compiles and executes the application but I gues I was wrong….

  • Gary Lesperance

    I had the same problem but your suggestion above did not work. You missed the most obvious problem which is that Java is case sensitive. If you reference the class as Helloworld in the script and then try to run it using java -classpath . helloworld (with the file actually named helloworld.class) then you will get the same error referenced above. The problem is the upper case “H” in the script and then the file starting with a lower case “h”.

    • GXOne

      OMG Thankyou After 5 Hours Thankyou.. with that advice it all works exactly the way it should LOL

  • nice

    hi to all

    too , i have error :

    Exception in thread “main” java.lang.NoClassDefFoundError: nameclass

    help me.

    • Crimson

      hi guys,

      I got this error when i made the mistake of running the class file. Make sure you are running the job correctly (fyi, I’m running vista):

      Correct: C:UsersCrimsonteaching> java Example

      Incorrect: C:UsersCrimsonteaching> java Example.class

      This is really easy to forget about, especially if you’re used to using an IDE like Eclipse, which was the case for me. I scratched my head for a little while and feel really dumb now.

      • neusbloed

        Crimson you finally made me understand why I was doing it not properly. I use Eclipse too. I’m going to feel really dumb now but I’m really happy I can run my files.

      • iedoc

        WOW! finally! that was it, just don’t put the extension on it! damn, thank you!

      • Nehadhmn

        o god!!!! u’r my savior!!!! so dis was it!! i was using d extension along…. o gosh… thnx a lot!! thnx a million crimson!!! mmmuuaahh!! thnx a lot!!

      • Awoo100

        What a deuchebag why didnt I think of this!

  • desperado

    i used textpad and i still got the same error, can anyone tell me what’s wrong?

  • Thomaso

    Thanks sooo much. if the java – classpath . helloworld doesnt work it is probably due to spacing and upper lower case letter problem.

    for me i didnt put a space after java and a space either side of the full stop. and i forgot to write my class with an upper case letter which is how it was saved.

    java(space) -classpath(space) . (space)Welcome1

    • Pandian

      thank u very very much…. the spaces helped me a lot….

    • Vin

      Thanks Thomaso.. it worked.. !!

  • jango19

    Exception in thread “main” java.lang.NoClassDefFoundError: Receiver/class
    Caused by: java.lang.ClassNotFoundException: Receiver.class
    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:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: Receiver.class. Program will exit.

    where Receiver is my class..code is getting compiled perfectly but when i run its givin the above error..

    • Ram

      Hi ,

      First set the JAVA_HOME variable with your bin directory.
      then try to run .it will help u.

      Regards
      Ram Yadav

  • Anonymous

    hello ,i got a problem while executing a sample java program.
    error is java.lang.NoClassDefFoundError: and im using jdk 1.6 version .
    someone helpout this

  • aravind

    thanq very much for giving the solution…….

  • nabil

    Awesome.
    It worked great

  • hello

    hey im not trieng to program a file or anything like taht. im just trieng to play a private game server and i keep getting the error message Exception in thread “main” java.lang.nodeffound: joader i have no idea how to fix it can anyone help? my CLASSPATH is C:Program FilesJavajdk1.5.0_18bin; and my PATH in C:Program FilesJavajdk1.5.0_18bin

    anyone help?

    • hello

      hey this is me hello again and please dont post anything too confusing i have no knowledge of java except for classpath and path so please keep it simple

    • hello

      and instead of joader its loader sorry for that

  • Kieran Taylor

    !!ALERT!! !!ALERT!!

    I just followed every suggestion in this string and no dice…

    FINALLY I GOT IT —-> (on Windows XP) MAKE SURE YOU COMPILE YOUR PROGRAM WITH C:…javac ClassName.java before you try to execute with C:…java ClassName

    You will know your program is compiled when you find a ClassName.class file in the same folder as your original ClassName.java program.

    Hope this helps the last desperate few.
    And yes, of course, make sure your path and classpath are correctly configured.

    • Loser

      Worked for me !!!

  • sixlead

    You will also get this error if you append the .class designator when you try to run it. as
    java HelloWorld.class

    java is expecting a class so the .class suffix is not necessary

    of course your class path might be wrong also ;-)

  • Anonymous

    Does not work

  • Ian

    Thank you – this is so helphul for me at the moment

    If you are also dependent on a jar file in the same folder you may need to have something like
    java -classpath .;./dependent.jar helloworld

    • Michael

      THIS THIS THIS, finally. I’ve been trying to fix this for a while and this was exactly the solution I needed.

  • rahul agarwal

    thanks for the replies that have been posted….
    i am so glad that my problem has been solved…

  • Name

    THANK YOU! My God this problem was so annoying

    • http://foo.foo foo

      I found out that having package definition in the class (“package foo.my.java.app;”) causes NoClassDefFoundError at runtime. When I removed the package line it worked fine.

  • Anonymous

    Gret thank you. I had the problem with the simplest program and the code was published on a book so I thought there can be nothing wrong with it.
    THANK YOU again :)

  • vazeer

    Thank You it really worked for me

  • Anonymous

    That worked! Thanks a lot,

    It would probably help if you explicity indicate that the extension “.class” should not be used when using “-classpath” .

  • Anonymous

    Ops, should’ve read the above comments first!

    my bad.. lol

  • Anonymous

    Well, I’m currently making my own chatserver in java, and when i compile with cmd, i get this error. Any help? I’m using the guide on Hello World on compiling and making classes.

  • Anonymous

    for coming out from this type of error
    we can run the programm by using diffrn style..
    like

    java -cp . className

    • Anonymous

      It might be due to packages.
      Try removing any “package” from the top of your *.java files.

    • naveen

      thanks a lot abdul, i have been trying to solve this problem for 7 hrs !
      finally i got the solution

    • Priyadarshini

      Hey adul,
      this really worked.
      May i know why this happens?

      When i execute the program using java classname
      i get Exception in thread “main” java.lang.NoClassDefFoundError: classname.

      However when i executed using java -cp . classname it really worked.
      Reason please.

  • Anonymous

    I am getting the class path error.My XYZ.java compiles good..When i run the program i and getting the below error..

    I had set the Classpath for the dependency jar and the Java_HOME = C:Program FilesJavajdk1.5.0_20bin
    C:Program FilesDDEForJavaexamplescomjavapartsddeexamples>java -cp . Excel
    Async
    Exception in thread “main” java.lang.UnsupportedClassVersionError: ExcelAsync (U
    nsupported major.minor version 49.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
    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)

    Any help would be appreciated//
    Thanks
    Shelli

    • Anonymous

      C:javaprog>java HelloWorld
      Exception in thread “main” java.lang.UnsupportedClassVersionError: HelloWorld (U
      nsupported major.minor version 50.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)

      C:javaprog>

  • Anonymous

    this happening 2 me, now i cant play a runescape private server thats 508, help me please?

  • b00red

    i don’t understand this ‘Executing your program using this command should correct the problem:
    java -classpath . helloworld’ ?
    where / how do i execute with another classpath?

  • Hamhama

    For a beginner you may get this error also if you run:
    java helloworld.class
    Instead try to run:
    java helloworld

  • Anonymous

    Okay, here’s the mistake I made (which almost drove me crazy):
    set classpath = .;M:;C:Program FilesJavajre1.6.0_14bin;
    is NOT the same as:
    set classpath=.;M:;C:Program FilesJavajre1.6.0_14bin;
    If you put spaces around the ‘=’ it won’t work. The file would always compile but would only run without the package designation. As soon as I added the ‘package’ statement at the top I could compile it but it would always give the above error when I tried to run it. Hope this helps someone.

  • Anonymous

    No, java -classpath . helloworld did not work. What next?

  • Anonymous

    Thanks, It helped

    • Ankzz

      It works.. One needs to pay heed to what has been said… Follow it step wise and U wont get any error

  • Anonymous

    superb information. excellent !

  • Anonymous

    Hi every one.

    I have installed red5 server on my machine and also JDK version of 1_5_0_11

    java -classpath C:Program FilesRed5red5.jar F:Video Chatred5chatv2.1JAVA-RED5srcchatapplication.java

    but when I tryed to compile to get my application.class file using above shown command on command promt I got error : Exception in thread “main” java.lang.NoClassDefFoundError: FilesRed5red5/jar

  • Anonymous

    thnx…great work buddy.It solved the problem for me.thanks a lot.

  • Anonymous

    Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/xml/serializer/TreeWalker
    at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:823)
    at com.pg.EDICustomize.EDISplit204.generateTarget(EDISplit204.java:353)
    at com.pg.EDICustomize.EDISplit204.execute(EDISplit204.java:99)
    at com.pg.EDICustomize.EDISplit204.main(EDISplit204.java:392)
    Caused by: java.lang.ClassNotFoundException: org.apache.xml.serializer.TreeWalker
    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:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    … 4 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)

    i got this error please help me to resolve this

  • Kevin

    I had this issue on linux. Turned out it was simply that the path had a space in it. When this was changed it worked fine.

  • Anonymous

    how do you execute it with THAT command? like what do you do? where do you type that in (java -classpath)?

  • Anonymous

    Ya, I’ve read all of these comments and have no clue where to type the java -classpath . XYZ

  • Anonymous

    Thanks … this works for me… I have been seem this type before but I was typeing ‘.’ close to ‘-classpath’ …

  • Anonymous

    thanks a lot it was really heplful..

  • Alan

    I just started learning java using the Eclipse IDE. My java for idiots book (ok for dummies) gave me some code that uses swing to produce a message box. There are 2 classes (the book is demonstrating objects).
    It ran fine from within eclipse, but if I tried running it from a command line it wouldn’t work. I got the java.lang.NoClassDefFoundError.
    I’ve searched the net and tried the -classpath . approach and still had no joy.
    I then found a post here
    http://bytes.com/topic/java/answers/15627-java-lang-noclassdeffounderror#post63668
    which refers to the package name as being an issue. I tried following the instructions but still had the issue. Eventually I removed the package definition from both my source files, recompiled and it runs fine. No classpath definition needed.

    Cheers
    Alan
    W00t !

  • Anonymous

    yes.. a dot .. it means, that it will search for classes bytecode in the current directory !

    you can also tell java to search the current directory with the -classpath parameter

    > java -classpath . Hello

    Problems like this can really discourage java newbies, and that moment was very embarassing :)

  • Setare

    thank you for your help in solving this java error.

  • Anonymous

    There are many correct answers here but not really clear to a java noob like me. After pulling my hair out for an hour and reading the answers over and over again it finally struck me.

    The answer for me is this: You should give the path to the directory where your to be executed .class file is, from the directory where you execute it from as you classpath.

    /program/Java/$: Javac hello.java
    /program/Java/$: java hello

    Hello!!

    If i now want to execute it from /program

    /program$: java -classpath ./Java hello

    Hello!!

    or from the root /

    /$: java -classpath ./program/Java hello

    Hello!!

    Hope this makes sense for the ones who did not get it the first ten times like myself.

  • Anonymous

    Thanks! this was helpful for me to resolve a pestering issue!

  • kiran

    while intepreting a program in java dont put .java after class name otherwise u will get (thread “main” java.lang.NoClassDefFoundError:)

    • Anonymous

      following is my simple awt program it get compile successfully
      but during run it generates following error
      Exception in thread “main” java.lang.NoClassDefFoundError: sampleframe (wrong na
      me: components/sampleframe)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
      4)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
      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:268)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

      • Anonymous

        pls pls help me

  • Chitre Mangesh

    HI Everyone .
    Following should be checked:=
    Primary check for java -version, if it returns values then installation is proper else re-install
    (Installation path may vary… check yours accordingly …..)

    1)Set JAVA_HOME to C:/Program Files/Java/jdk1.6.0_12
    2) Set CLASSPATH environment to C:/Program Files/Java/jdk1.6.0_12/jre/lib;./;
    (Note :- ” ./ ” )
    3)Set Path to C:Program FilesJavajdk1.6.0_12bin

    • Anonymous

      Thanx ……….this worked !!!!!!!!

  • Banananana

    If the class you wanna execute is in a package, do this:

    java -classpath . packagename.classname

    Don’t forget the spaces after “classpath” and the first “.” and note that there aren’t spaces after your package name and the following period.

  • Anonymous

    im getting the error java.lang.NoClassDefFoundError:
    my classpath is c:jdk1.5lib.
    give me a help pls

  • joe

    alright, im pretty much haveing the scape problem as every1 else but, im such a newb to using computers… my problem says “NoClassDefFoundError:” how the HECK do i fix it???

    • joe

      haveing=having and scape=same (sry typos)

  • Anonymous

    thank you soooooo muchhhhh!!!!!! this comment has helpd me sort out a problem that i wasn’t being able to do for days!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! i tried doing everything possible, including setting path & classpath variables, but nothing helped……. thank u so muchhhhhh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Anonymous

    i finally got it….
    first set the CLASSPATH to the location of the folder where you have saved the .java files.
    second, make sure that in the PATH, you got a setting describing where the installation files are- i.e C:Program Filesjavajdk 1.6.0_18bin.
    also ensure you got QTJAVA set to the location of the jre bin file-i.e c:program files.
    lastly, create a variable called JAVA_HOME containing the following values….the location for the jdk bin. I.E c:
    ALL THE BEST IT WORKED FOR ME

  • Anonymous

    hi,
    how can i run a java program by cmd in winxp
    for example ,
    a java pgm compiled and got the class file
    pgm name=hello.java
    D:javac hello.java===got the class hello.class in D: drive i copied that class file the paste in E:
    then how i run the pgm from D:
    D:java -cp E:hello
    but hitting enter java.lang.NoClassDefFoundError: this error is comming

    what is the problem please help me

    • Anonymous

      the problem was i didnt put space
      D:java -cp E: *hello
      the * is the space i forgot
      This may help other

  • Nitin

    Thanks.. was helpful..

  • Al

    I had this problem and this suggestion did not work.
    I figured out that when you have, lets say a class called X, and at the top of the java file it does NOT have a package statement, the class will compile and run with javac and java with no problems.
    When you add a package statement and try to run the program with the line java X, it fails to run.
    You must go to the parent directory of the package directory and run the line
    java .X
    This works perfectly fine and solved my problem.
    Hope this helps!

    • Aa

      Thanks Al !! This is what I looked for!!!

  • Anonymous

    Everywhere I look I see the classpath as an issue but even though I got the same error, classpath was not the problem.

    If you know your classpath is set up right check you source file. In my case, I had named my class one thing and tried to run it with the name I thought I had called in the source.

    For example, my source said class VolcanoApplicataion when I mean VolcanoApplication so when I compiled it went fine but when I tried to run it as the name i truly meant I got the error in question.

    Hope it helps and spread it around cause everywhere I looked left out this tidbit

    Andrew Witherspoon

  • Anonymous

    Thank u so much . Your idea helped me a lot .

  • Anonymous

    Don’t forget your classname is CASE SENSITIVE.

    Here’s how I do it:

    Open CMD.
    (I keep my files in Documents)

    cdusersdubedocuments

    set PATH=%PATH%;C:Program FilesJavajdk1.6.0_03bin

    javac SampleProg.java

    java SampleProg

    That’s it. CASE SENSITIVE.

    • Mahrizal

      thanks , it usefull for me

      thanks a lot

  • Marin van Zandvoort

    Many thanks!

    I almost give up, but then I found your short-and-really-to-the-point answer to the problem.

  • Anonymous

    Although I’ve read through all of the postings here and elsewhere & already tried all of those recommendations and re-installing the Java JDK, I keep getting the error of NoClassDefFoundError.

    Also, following various changes I made to suit the recommendations listed about this problem and possible solutions, my PATH, Java_HOME, and Classpath variables are set to the following:

    a) PATH system variable:
    %SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;C:Program FilesMicrosoft SQL Server90Toolsbinn;C:Program FilesCommon FilesRoxio Shared9.0DLLShared;C:Program FilesCommon FilesRoxio SharedDLLShared;C:Program FilesQuickTimeQTSystem;C:Program FilesJavajdk1.6.0_19bin
    hared;C:Program FilesCommon FilesRoxio SharedDLLShared;C:Program FilesQuickTimeQTSystem;C:Program FilesJavajdk1.6.0_19bin;C:Program FilesPalmSDK
    bin;C:Program FilesPalmSDKbinnovacom

    b) Classpath:
    .;

    c) Java_Home:
    C:Program FilesJavajdk1.6.0_19

    Also, in Eclipse, I have the “helloUser” class stored in a package named “HelloUser” and am running Vista with the User Account Control feature disabled. In addition, when using the javac command with the helloUser.java class from the C:users[myName]workspaceHelloUsersrchelloUser directory, it appears that the helloUser.java class gets compiled successfully. The problem appears to be isolated to using the java command against the compiled version of the class.

    Any thoughts?

    Errors shown when trying to execute the class from the command-line:
    ————-
    c:Users[myName]workspaceHelloUsersrchelloUser>java HelloUser
    Exception in thread “main” java.lang.NoClassDefFoundError: HelloUser (wrong nam
    : helloUser/HelloUser)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    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$000(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)
    Could not find the main class: HelloUser. Program will exit.

  • Anonymous

    the

  • Anonymous

    thing

  • Anonymous

    alert(‘hi’)

    • Anonymous

      good

    • Anonymous

      nice

  • Anonymous

    there is a exception error in swing

  • Anonymous

    I use windows 7, I know nothing about java. I’m trying to compile a script into this program/application using the ‘Compile-Scripts.bat’ thing that’s in the folder. when i click to compile it i get this message.

    Exception in thread “main” java.lang.No.ClassDefFoundfError: Scripts/ErrmmPwwndpapayas/java
    Caused by: java.lang.ClassNotFoundException: ScriptsErrmmPwwndpapayas.java
    at Java.net.URLClassLoader$1.run
    at java.security.AccessController.doPrivileged
    at java.net.URLClassLoader.findClass
    at java.lang.ClassLoader.loadClass
    at sun.misc.Launcher$AppClassLoader.loadClass
    at java.lang.ClassLoader.loadClass
    at Java.lang.ClassLoader.loadClassInternal
    Could not find the main class:ScriptsErrmmPwwndpapayas.java. Program will exit.
    Press any key to continue. . .

    I have tried really hard to read and understand/comprehend all the great information in this thread and other, but I am still unable to understand how to fix anything.
    If someone has yahoo messenger and can help me that’d be awesome. I could show you the folder and stuff with screen shots and maybe you could tell me what to do.
    potterman210@yahoo.com

    • Anonymous

      This is what the ‘Compile-Scripts’ bat looks like, hopefully it will help

      @ECHO OFF

      TITLE RSBot Scripts

      SET cc=java
      SET cflags=
      SET scripts=Scripts
      SET scriptspre=%scripts%Precompiled
      SET jarpathfile=Settingspath.txt

      IF NOT EXIST “%jarpathfile%” (
      ECHO Path file does not exist. Please run RSBot and try again.
      GOTO end
      )

      FOR /F “delims=” %%G IN (%jarpathfile%) DO SET jarpath=%%G

      CALL FindJDK.bat

      IF NOT EXIST %scripts%*.java (
      ECHO No .java script source files found.
      GOTO end
      )

      ECHO Compiling scripts
      ECHO. > “%scripts%.class”
      DEL /F /Q “%scripts%*.class” > NUL
      “%cc%” %cflags% -cp “%jarpath%” %scripts%*.java

      :end
      PAUSE
      EXIT

  • Anonymous

    if you have defined a classpath then go to that location and execute the pgm, else you should not be having problems

    • Anonymous

      What does that mean?

  • Anonymous

    thank you!!

  • Dhiroj

    many many thanx
    really a helpful data

  • Anil

    There is nothing problem just set the JAVA_HOME path and PATH of java installation folder.
    default path of JAVA_HOME is C:Program FilesJavajdk1.5.0
    and PATH is C:Program FilesJavajdk1.5.0bin

    above all this, set in environmental variable in my computer.

  • Jenefar Esther04

    its very useful to me.thanks

  • Renuka salavi

    i used this still i found the same error
    Exception in thread “main” java.lang.NoClassDefFoundError: menu (wrong na
    u)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.
    4)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    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:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

    • HugeIdea

      You should miss the .; in front of your classpath. add those to your classpath, and it should work fine.

  • Fr

    Man.. Thanks ! I was stuck on this for like 2 hours :D

  • Ollan_misa

    wath path i can use in window 7???? tnx im stuck doing my home work :/

  • Ds

    Solution is:

    Hi there,
    Problem often occurs when re?nstalling, easy to fix: i right-click on my computer, Properties, select the Advanced Tab, then press the Environment Variables button and a window pops up. At the bottom there’s is a button with System Variables, press it. All you have to do is delete CLASSPATH variables in the list.

    • Catony

      Thanks Ds, this really solved my problem for good. There was another CLASSPATH variable listed–hope my deleting it won’t screw up that program.

      I’m using TextPad which would compile my program fine but not run it without that stupid error, and it was a bother to go to the DOS command prompt to run the program using “java -classpath . Classname” though that did work too.

      Thanks everyone, I’m hoping to stick with it.

  • Svsreddy01

    Exception in thread “main” java.lang.NoClassDefFoundError
    this error will occur wat i do plese give me answer

  • Live_long6

    My class path is proper….even i am getting .class file…but it show me java.lang.noclassdeffounderror error plz help me thxs..

  • Suntro2007

    After a full day of research I could find the solution to the problem.

    I created a java program Pet.java under a package com.xyz.client under the folder sturcture
    C:Documents and SettingsspatroWorkspacespositronmyProjectsrc
    so my Pet.java resides in
    C:Documents and SettingsspatroWorkspacespositronmyProjectsrccomxyzclient

    I set my classpath to C:Documents and settingsspatroWorkspacespositronmyProjectsrc

    by doing set CLASSPATH=%CLASSPATH%;C:Documents and settingsspatroWorkspacespositronmyProjectsrc

    to compile the program
    I changed to the directory where my Pet.java resides
    so I did
    cd C:Documents and SettingsspatroWorkspacespositronmyProjectsrccomxyzclient
    and there I executed the command
    javac Pet.java
    and then I switched my directory to
    my src folder where my package reside i.e
    C:Documents and settingsspatroWorkspacespositronmyProjectsrc

    and here I executed the command
    java -cp . com.xyz.client.Pet

    Note:- the . is for the current directory.

    Hope, this explanation will help others who struggled for this like me.

    • TomDh

      Thank you. This was what i was looking for.

      in commandprompt go to the global path of your application:
      d:applicationsmyApplicationbin

      execute your application
      d:applicationsmyApplicationbin>java -cp com.package.model.myClass

      change the JAVA_HOME to
      d:applicationsmyApplicationbin

  • Reeteshdas

    the above solution does not solve the problem.

    • Shg23

      I solved that callin my program without .class extention

  • Conor

    Holy crap! Worked like a charm!

  • Nvenkat Ede

    what is the permanent sol for java.lang.NoClassDefFoundError Exception without writing -classpath explicitly when ever we have to run the .class file

  • Girish0204

    When I execute hello.java i am getting the following error:
    C:>java HelloWorld.java
    Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorld/j
    Caused by: java.lang.ClassNotFoundException: HelloWorld.java
    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)
    Could not find the main class: HelloWorld.java. Program will exit.

    Note: I have installed Java under C:Program FilesJavajdk1.6.0_21

    Not sure what is the problem. Please help

    Is there any problem in setting the path and class path?

  • Anonymous

    Helped me a lot

  • Venkatesh Marni

    set classpath=.; in command prompt

  • Fredd

    Debes de asegurarte que el .class se este guardando en el directorio actua

  • Silver_manta

    Thanks so much!!!!

  • Veb_405

    thank u very much to solve my problem

  • Lindsay

    I’m using RMIC to generate a stub, but I keep getting ClassNotFound exception. Some code works and some code doesn’t. The code works on my partner’s computer, not mine, PLEASE help. I can get the RMIC to work by specifying -classpath, but I can’t use the dot to specify the current directory and my server fails to start up.

  • Mail2yugi

    thanks its working

  • Sarav Preet Singh

    very very thanx

  • vineet

    i’m srry
    it didn’t work
    when i compile my program, it compiles successfully but when i run the command
    java -classpath.A
    it shows :

    unrecoginzed option: -classpath.A
    couldnot create the java virtual machine

  • Amit

    it’s really helpfull..
    Thanx

  • Utkarsh

    not working yet

  • Amara

    This is the error thats troubling me :

    Collapse

    C:Documents and SettingsxxxxDesktopJava Files New>javac MSWord.java

    C:Documents and SettingsxxxxDesktopJava Files New>java MSWord
    Exception in thread “main” java.lang.NoClassDefFoundError: MSWord (wrong name: o
    rg/jinterop/dcom/test/MSWord)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    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$000(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)
    Could not find the main class: MSWord. Program will exit.

    Environment Variables:

    JAVA_HOME C:glassfishv3jdk

    CLASSPATH .;C:Program FilesQuickTimeQTSystemQTJava.zip;C:Documents and SettingsxxxxDesktopj-Interoplibj-interop.jar;C:Documents and SettingsxxxxDesktopj-Interoplibjcifs-1.2.19.jar;C:Documents and SettingsxxxxDesktopj-Interoplibj-interopdeps.jar;C:Documents and SettingsxxxxDesktopj-InteroplibprogIdVsClsidDB.properties;C:glassfishv3jdkbin;C:Documents and SettingsxxxxDesktopJava Files New;C:glassfishv3jdklib;

    Path %SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;C:Program FilesQuickTimeQTSystem;C:gwt-2.1.0;%ANT_HOME%bin;C:Program FilesJavajre6bin;C:glassfishv3jdkbin;

    Details:
    Installed Java(TM) 6 update 22
    Java(TM) 6 update 5
    C:Program FilesJavajre1.6.0_05
    C:Program FilesJavajre6.0
    C:glassfishv3jdk

    Tools.jar is present in all the lib and bin folders of the above locations.

    Tried all these:
    http://www.tech-recipes.com/rx/826/java-exception-in-thread-main-javalangnoclassdeffounderror/^]

    http://www.jguru.com/faq/view.jsp?EID=455768&page=1^]

    Nothing has resolved my issue, i am new to java and very confused on whats happening!! I knew the error is with classpath but i have tried all possible combinations.

    Any suggestions or advices!! Please let me know if you need any more info!!

  • Amara

    I got it resolved when i used

    C:Documents and SettingsxxxxDesktopJava Files New>java org.jinterop.dcom.test.MSWord

    • ANIMEMANIX

      were do i write that,
      im making a rs server
      wat is a classpath? lol

  • http://twitter.com/triastanto Rahmadhany T

    Make sure you already set you CLASSPATH environment variable.
    Read this section carefully:
    Understanding the class path and package names
    on http://download.oracle.com/javase/1.3/docs/tooldocs/win32/classpath.html
    I assume you already knew about package concept in java.

  • Sowmya

    Exception in thread “main” java.lang.NoClassDefFoundError: jomp/compiler/jomp

    i get this error wen i try to compile a simple helloworld.jomp file as
    java jomp.compiler.jomp helloworld

    m using jomp1.0b i have also set the class path n path
    can anyone tell me y i get this error

  • Duckiesgrandpa

    I just learned that Capitalization is also important. If your class file is named HelloWorld then helloworld won’t work.

  • Chap

    Starting L2J Game Server.

    Exception in thread “main” java.lang.NoClassDefFoundError: com/l2jserver/gameser
    ver/GameServer
    Caused by: java.lang.ClassNotFoundException: com.l2jserver.gameserver.GameServer

    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)
    Could not find the main class: com.l2jserver.gameserver.GameServer. Program wil
    l exit.

    Server terminated abnormaly

    server terminated

    Press any key to continue . . .

  • Manish

    Hi guyz I am looking for a program which print everytime on pressing enter Hello using the thread in Java

  • Manish

    can anyone tell me how we can write a program to open an internet explorer in Java

  • who885

    hey guys im having alot of troublel latly im trying to make a rsps but i keep getting this errore
    Exception in thread “main” java.lang.NoClassDefFoundError: client
    Caused by: java.lang.ClassNotFoundException: client
    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)
    Could not find the main class: client. Program will exit.
    Press any key to continue . . .

    if you can help great

    • srileo

      set environmental variables first…

      • Raymond

        Sorry, i also face this problem.

        I not really know bout java.

        What mean of set environmental variables?
        got example?

  • P4_pacific007

    when I compile a simple prog it points error towards the dot between
    system.out as in system.out.printin()

    • Chitra_12

      its System.out.println()
      first character ‘s’ should be in uppercase

  • ravi kiran naidu

    it’s working i liked it

  • Chitra_12

    When im executing the simple java program ..
    i get
    Exception in thread “main” java.lang.NoClassDefFoundError: classname.

  • Chitra_12

    what commands should give now if help me

  • alien

    this is great. thank you very much.

    my problem was the missing ./ in CLASSPATH

  • L_savitha

    Can any one suggest me how to proceed with this. i tried all possible methods.
    On clicking on one button, it should print on the console. it should keep printing until another button is pressed

  • Luis Adrián Ferreyra

    THIS IS A MESSAGE FOR EVERYONE WHO STILL HAVE THIS PROBLEM

    I’m sure you’ve tried everything written in this forum. After looking for an answer at Oracle’s website, I’ve finally found it.

    WHAT YOU’VE GOT TO DO is to stand in the src folder of your proyect, NOT IN YOUR PACKAGE. then, use this syntax:

    java -cp . PACKAGE.CLASS

    remember, your cd must be your proyect/src and follow the syntax above.

  • Chiragpatel

    just put .; in ur class path and it ll work

    this is message from GOD

  • Chiragpatel

    .: period semicolon

  • Imran Sharif

    i have a problem
    build.xml for jboss aop has an error

    “” Exception in thread “main” java.lang.NoClassDefFoundError: org/jboss/util/file/ArchiveBrowser$Filter “”

    can any body plz help what s the problem ???

  • Magnus

    Apparently it matters in which order you put the class-files when creating your jar-file. If you’re using superclasses/subclasses you have to put the superclass first in the command! Like so: “jar cvmf manifest.txt myfile.jar SuperClass.class SubClass.class TestClass.class”

  • Onkdurga

    It is very nice…gives the solution exactly

  • vinay singh

    Hey hi well i m trying to run a simple prog that having a object of another class but it is giving error the symbol not found evn the class file is in same directory………

  • awsmvini

    hello help me out plz ……..m tryng to run a java prog which is having connectivity with mysql i pasted the driver in javalibext folder evn its is giving error that driver not found exception in main………

  • Rybka2323

    omg… nothing work ;( what i need to do!? HELP!!!!!

  • Jagadish_t

    This was really saved my problem. I changed the CLASSPATH variable to add the current directory. Which is “.”, This saved me my life. Thanks for the valuable post.

  • dhruv

    thank u sir thank u , u saved my receding hairline

  • Pam

    Hi I have this error in my loginserver  Exception in thread “main” java.lang.NoClassDefFoundError: LOGIN_HOSTNAME i need help , what should I add in my CLASSPATH?

  • M Bhagyabhushan

     frustated wit this problem and got solution

  • Kaucuk

    Watch out the case sensitivity like class hello, file hello etc

  • yeyeye

    waw, thanks very much! You are really helpful! Your recipe is delicious! LOL

  • http://javarevisited.blogspot.com/2011/01/how-classpath-work-in-java.html JP@ classpath in Java

    nice recipe. I also found this link quite useful
    3 ways to resolve NoClassDefFoundError in Java

     

  • http://javarevisited.blogspot.com/2011/01/how-classpath-work-in-java.html JP@ classpath in Java

    nice recipe. I also found this link quite useful
    3 ways to resolve NoClassDefFoundError in Java

     

  • Shawna

    omg i have been working on this FOREVER and none of the many suggestions worked. But first i should tell you that every single step I had huge problems but I never gave up because I have successfully configured a few years ago when I first tried to teach myself Java. Anyway, I have made many mistakes configuing the CLASSPATH so I really didn’t know what to fix. After finally getting it to compile successfully (creating the class file) it still wouldn’t work. Finally I tried this…and I didn’t see it anywhere in this blog so I hope it helps everyone after me. In addition to what you have in the CLASSPATH (int the envir. varables)add the following without deleting anything you already have there:

    .;C:J24work

    instead of J24work you should enter the exact path to where you are puting you .java and .class files which is probably different from where you JDK is for some people.

    I truly hope I explained this well and it helps someone.

  • madu

    how to get only two precision after decimal in java..eg.3.8989E-34,MUST BE MADE TO 3.89

  • Anthony

    Thanks so very much for this simple and clear solution.i had set all variables and did a lot of copying from one directory to another but to no avail until i issued this simple command and it ran perfectly.
    God bless you!
    Thanks again

  • Sushant

    Hey was trying to run the class file from cmd after a long years and had stuck with this beginners time error. But suggestion of including classpath of the .class file using set classpath = and then running java command worked really well.

    Thanks a ton !!!

  • nash

    @Suntro2007: u saved me man . I tried all other solutions but u r solution only worked . finally before leaving home i Just tried ur solution for a last try. For my surprise it worked. THNXman

    @all :thnx

  • Nivedha

    hai i need to know how the mapping between swing and servlet happening

  • orbanbalage

    @Luis Adrián Ferreyra said on March 2, 2011

    WOW man, so simple, but really I had to struggle through all things to find your final comment. thx bro :)

  • nagaraj

    hi am using jdk 1.4, wheni try to build the program using ANT it shows error like Exception in thread “main” java.lang.NoClassDefFoundError

    please help me out !

  • sivasankar

    hi every one…
    when i try to run Hibernate annotation basic program it show this error
    please help me………….

    Exception in thread “main” java.lang.Error: Unresolved compilation problem:

    at edu.test.Example.main(Example.java:17)

  • C Mihai

    Use this simple command before running the FileName.class in cmd :
    set classpath=%classpath%;.;
    this is all

  • Ravi Bhosle

    Its really helpfull……………
    but i don’t know why it gives error even though when i have set the classpath correctly.

  • jayashree

    Exception in thread “main” java.lang.NoClassDefFoundError: nameclass
    this error is being came in my project plz help me

  • Taras

    Thank u man! spent 3 hours to solve this problem… works fine!!!

  • Prethesh Kumar Bhalotia

    Very useful. I got stuck on this error but after going through this article. It made easy.

  • Fida

    Tx a ton!

  • satti

    Very use full…..
    Thank you

  • vijeta

    I’m still getting .Java: Exception in thread main java.lang.NoClassDefFoundError.
    even i have done every thing………..

  • Soundar

    Its working for my EJB program… Thank u man…:-)

  • Cepeclire

    Approvo compiutamente come le idee espresse fino ad oggi. Andate avanti in questo modo.

  • piyush

    yes the answer java -classpath . helloworld is really helpful………

  • duycuong

    thanks for help,it’s very good!

    Hello.java
    cmd ( javac ~/works/project/src/packages1/Hello.java ) NEXT ( cd ~/works/project/src BEFORE java -classpath . packages1.Hello) great work :)

  • vaishak mohan p

    Very helpful, Thank U Bro

  • Anonymous

    Long live David for this, saved my day.

  • Ronaldcep

    Hi to all members on this community i am thanks to the administrator of this forum for approve my account i am sure here i got better knowledge thanks again. My name is Ronald.