can't run java program in dos prompt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ValValVal
    New Member
    • Oct 2008
    • 27

    can't run java program in dos prompt

    Hi.
    I created simple Hello World application that compiles&runs ok in NetBeans 6.1 but when I try to run it with command line

    java main

    it says that:
    Code:
    Exception in thread "main" java.lang.NoClassFoundDefFoundError:main(wrong name).
    and some other thing

    Advice very appreciated.
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    Well for starters you are trying to execute your source code. You need to use the compiled class file, not the Java source file. The command should be java main.class. The class also has to have a main method, and any dependant classes have to be in the class path.

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      You want to do this:
      Code:
      javac main.java
      java main
      Greetings,
      Nepomuk

      Comment

      • ValValVal
        New Member
        • Oct 2008
        • 27

        #4
        By mistake I wrote
        java main.java

        in my previous post.

        Actually what I entered was
        java main

        After which compiler said that it cannot find main class.

        Comment

        • Nepomuk
          Recognized Expert Specialist
          • Aug 2007
          • 3111

          #5
          Well, first of all, the compiler is javac - this is the java virtual machine (jvm).

          Now, does main.java contain a main method? And also, is it in any package (which would be indicated by package name-of-the-package at the top of main.java)?

          Oh, and do any other files belong to the project?

          Greetings,
          Nepomuk

          Comment

          Working...