java.lang.NoClassDefFoundError ?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: java.lang.NoClassDefFoundError ?

  1. #1
    Join Date
    Oct 2005
    Posts
    3

    java.lang.NoClassDefFoundError ?

    Hi

    I was able to compile and run java files until a few day ago. Yesterday when I tried to run a file I got: "java.lang.NoClassDefFoundError: TestClass Exception in thread main "

    I am sure that PATH is ok because I havent changed anything there. NetBeans works fine but I don't want to work with NetBeans because it adds a lot of folders and things that I dont like and I am doing thing for learing.

    I reinstalled java but to no good.

    Any suggestion?

  2. #2
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    Sounds like your classpath doesn't contain a path to TestClass.
    Can you show/paste here the commandline you are entering and the results?
    Also if you are using the CLASSPATH environ variable, show its value.

    The PATH env var is NOT related to the CLASSPATH var. PATH tells the OS where to find commands. CLASSPATH is used by Java to find class definitions.

    What's changed? If it used to work and doesn't now, what did you change? Can you change it back?

  3. #3
    Join Date
    Oct 2005
    Posts
    3
    Thanks Norm for reply

    I edit this topic to add this:
    I noticed you said: "CLASSPATH is used by Java to find class definitions." so I changed CLASSPATH to the directory that I had my class and it worked. Thanks but do I need to change it for every different directory that I have my java files there?

    and the rest is what I typed before reaching the above result.

    Actually since the problem started I changed and changed PATH and CLASSPATH to whatever websites suggested but no hope. This is what I have now:

    PATH: D:\programs\Java\jdk1.5.0_04\bin
    CLASSPATH: D:\programs\Java\jre1.5.0_04\lib - I tried D:\programs\Java\jre1.5.0_04\lib\ext and D:\programs\Java\jdk1.5.0_04\bin as well. -

    and my test program:
    PHP Code:
    import java.lang.*;
    class 
    TestClass{
        public static 
    void main(String[] args){
        
        }

    It compiles ok but when I try to run it I get this error:

    PHP Code:
    Exception in thread "main" java.lang.NoClassDefFoundErrorTestClass 
    And I add that I can run the code using NetBeans.
    Last edited by mahmood; 10-09-2005 at 01:08 PM.

  4. #4
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    You shouldn't have to set the CLASSPATH to the java SDK files. You should NOT put any of your programs in the java folders.

    I don't see the commandline you entered as per earlier request:

    >>>Can you show/paste here the commandline you are entering and the results?

    What folder are you in when you issure the command? What files are in that folder?

  5. #5
    Join Date
    Oct 2005
    Posts
    3
    Thanks for reply

    I noticed you said: "CLASSPATH is used by Java to find class definitions." so I changed CLASSPATH to the directory that I had my class and it worked. Thanks but do I need to change it for every different directory that I have my java class files are there?

  6. #6
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    Depends. All the classes to be used in an execution need to be found by java. So if a class is needed, then it should be on the classpath.
    A prefered method is to set the classpath with the java.exe command when you execute the program:

    java.exe -classpath <path>;. <pgm>

  7. #7
    Join Date
    Oct 2005
    Posts
    1

    Setting Classpath

    "I noticed you said: "CLASSPATH is used by Java to find class definitions." so I changed CLASSPATH to the directory that I had my class and it worked. Thanks but do I need to change it for every different directory that I have my java class files are there?"


    If I were you, to avoid that particular inconvenience I'd add the current directory to my classpath so that any programs in the current directory would be found. In Unix, I add "./" to the classpath, but in windows I imagine it would be ".\" instead.

  8. #8
    Join Date
    Oct 2005
    Posts
    1
    I had the same problem. All of a sudden (it felt) my java-progs stopped working with NoClassDefFoundError thrown, even hello world progs.

    The reason turned out to be that a program I installed (XML SPy) had added CLASSPATH as env variable. Now i had CLASSPATH=c:\XMLSpy. If I changed that to CLASSPATH=.;c:\XMLSpy my java-progs started working.
    It also works if I unset my CLASSPATH.

  9. #9
    Join Date
    Oct 2005
    Posts
    22
    set the classpath to you current directory(.) either in your environement variables or set teh classpath explicitly to you current directory. It will Work

    thanks
    G.Rajasekhar

Similar Threads

  1. java.lang.NoClassDefFoundError
    By srekcus in forum Java
    Replies: 2
    Last Post: 05-25-2005, 01:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center