• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 80954
522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)?
  •  
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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).
     
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
    Clean our rivers and oceans from home
    https://www.kickstarter.com/projects/paulwheaton/willow-feeders
    reply
      Bookmark Topic Watch Topic
    • New Topic