NoClassDefFoundError

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • greatjuli
    New Member
    • Jul 2007
    • 7

    NoClassDefFoundError

    Please i am trying to run a java application but i keep getting this error:
    NoClassDefFound Error
    However, if i run the file from the bin folder it works but i dont want to keep changing directory to the bin folder to run my applications. I want to run the file as long as i have the same folder where this file is saved as the active directory at comand line
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    This is a classpath error of some sort. If it can't find the class with main() in it, you need to add the folder with the class in it to the classpath. If it's something you've imported, add the folder where that source is to the classpath. I've never been entirely certain how one does this (I use Linux), but I believe if you compile (and possibly run) with the -classpath . flag (eg java -classpath . filename), it'll help this.

    Comment

    • Kid Programmer
      New Member
      • Mar 2008
      • 176

      #3
      This means you have not defined a class. Make sure you typed something like:
      Code:
      class BLAH {
      If it is a public class don't forget to save the file with the same name as the class.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Kid Programmer
        This means you have not defined a class. Make sure you typed something like:
        Code:
        class BLAH {
        If it is a public class don't forget to save the file with the same name as the class.
        That could be it but is unlikely; more likely is that the JVM can't find the class
        because it is not stored somewhere to where the classpath points. The classpath
        variable is a list of directories where the JVM searches for classes. For beginners
        it can be as simple as a '-classpath .' flag value which makes the JVM search for
        classes in the current directory.

        kind regards,

        Jos

        Comment

        Working...