• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.NoClassDefFoundError:  RSS feed

 
Amith Bhavikatti
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

i am tring to run a java program from commandline .
i included all classpaths while compiling the java file.
i included all environment variables.

i compiled it and i got the generated class file.
but still i cannot run the program.

This is the command and the error which i am getting:

E:\ECost>java MyProgram
Exception in thread "main" java.lang.NoClassDefFoundError: MyProgram (wrong name
: ECost/MyProgram)
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)


Please help me.
Thanks in Advance
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please supply more details.
  • Where is the MyProgram.class file? (Not a good name, by the way: the class name ought to make it obvious what the class is all about).
  • Have you got it in the folder you are using at present (use the "dir" instruction from the command-line on Windows to find it)?
  • Have you got a package declaration in MyProgram?
  • Have you set up a system or user CLASSPATH as a permanent environment variable (which is usually a mistake, despite what people tell you)?
  •  
    Jesper de Jong
    Java Cowboy
    Sheriff
    Posts: 16059
    88
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    E:\ECost>java MyProgram
    Exception in thread "main" java.lang.NoClassDefFoundError: MyProgram (wrong name: ECost/MyProgram)


    This suggests that your class MyProgram has a package statement:

    You're calling it the wrong way. Make sure that the base directory of the package in in the classpath, and specify the fully qualified name of the class (i.e. the package name, dot, class name) on the command line:

    E:\>java ECost.MyProgram

    or:

    C:\Somewhere>java -classpath E:\ ECost.MyProgram

    (note the space between E:\ and ECost.MyProgram).
     
    j srinivas
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well the exception occurs when your compiler tries to execute the class file.
    i assume your CLASS PATH variable and JAVA_HOME are not properly set.
    while setting class path include . also,because . specific to include current directory.

    If that is not the case,then type directory in your command prompt and try to find your file,i bet .class file would be missing.That means your working in wrong directory.



    Keep it simple not simpler.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!