Unknown compiler error with Java.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Daveyyy
    New Member
    • Sep 2007
    • 5

    Unknown compiler error with Java.

    Hi!

    I am not new to java by any means. But there is an error code which I have had described as a corrupt installation.

    I am a student and everyone else in the class seems to have had no issues with their install.

    Here is the code:

    // Program Name: Welcome
    // Program Description: A simple program that prints a welcome statement to the console.
    // Author: ???
    // Date: 09.05.07

    public class Welcome
    {
    public static void Main(String[] args)
    {
    System.out.prin t("Welcome to Java!");
    }

    }

    The error displayed is this:

    Exception in thread "main" java.lang.NoCla ssDefFoundError : Welcome/java

    As I said before everyone I have talked to said it is due to corrupt installation. Please help! I need Java to run properly if I am to pass. ^_^

    Thanks!

    Dave
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Daveyyy
    Hi!

    I am not new to java by any means. But there is an error code which I have had described as a corrupt installation.

    I am a student and everyone else in the class seems to have had no issues with their install.

    Here is the code:

    // Program Name: Welcome
    // Program Description: A simple program that prints a welcome statement to the console.
    // Author: ???
    // Date: 09.05.07

    public class Welcome
    {
    public static void Main(String[] args)
    {
    System.out.prin t("Welcome to Java!");
    }

    }

    The error displayed is this:

    Exception in thread "main" java.lang.NoCla ssDefFoundError : Welcome/java

    As I said before everyone I have talked to said it is due to corrupt installation. Please help! I need Java to run properly if I am to pass. ^_^

    Thanks!

    Dave
    Please use code tags if you have to post code.
    How did you compile the program?

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by Daveyyy
      Hi!

      I am not new to java by any means. But there is an error code which I have had described as a corrupt installation.

      I am a student and everyone else in the class seems to have had no issues with their install.

      Here is the code:

      [code=java]
      // Program Name: Welcome
      // Program Description: A simple program that prints a welcome statement to the console.
      // Author: ???
      // Date: 09.05.07

      public class Welcome
      {
      public static void Main(String[] args)
      {
      System.out.prin t("Welcome to Java!");
      }

      }
      [/code]
      The error displayed is this:

      Exception in thread "main" java.lang.NoCla ssDefFoundError : Welcome/java

      As I said before everyone I have talked to said it is due to corrupt installation. Please help! I need Java to run properly if I am to pass. ^_^

      Thanks!

      Dave
      Oh dear that must be bit rot on your harddisk; burn your computer before it spreads!
      Seriously though: haven't you read about a 'main' method, instead of a 'Main' method?

      Don't believe what people say about rotten installations and what have you; just
      check and check again what you did wrong: one little case mistake; that's it.

      Better check your classpath value as well before you start panicking again.

      kind regards,

      Jos

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        Originally posted by Daveyyy
        Hi!

        I am not new to java by any means. But there is an error code which I have had described as a corrupt installation.

        I am a student and everyone else in the class seems to have had no issues with their install.

        Here is the code:
        [CODE=java]
        // Program Name: Welcome
        // Program Description: A simple program that prints a welcome statement to the console.
        // Author: ???
        // Date: 09.05.07

        public class Welcome
        {
        public static void Main(String[] args)
        {
        System.out.prin t("Welcome to Java!");
        }

        }
        [/CODE]
        The error displayed is this:

        Exception in thread "main" java.lang.NoCla ssDefFoundError : Welcome/java

        As I said before everyone I have talked to said it is due to corrupt installation. Please help! I need Java to run properly if I am to pass. ^_^

        Thanks!

        Dave
        I think, the error is very simple: your main method is called Main instead of main. Changing that let me compile and run the program.

        Greetings,
        Nepomuk

        Comment

        • Daveyyy
          New Member
          • Sep 2007
          • 5

          #5
          Sorry but I forgot I had changed that before I posted. That isn't the problem. With the class named "main" the same issue comes up.
          I compile using the command prompt, as this is the way instructed in class.
          i.e. "javac Welcome.java" would be the line I use.

          However another thing I had neglected to mention was that it in fact does compile. It is when I attempt to run the program that the issue arises.

          Again the "Main" in the code I submitted is actually a fix I attempted prior to submitting.

          Also, I have tried a complete un-install and re-install. The only other forum I have gone to said that the error comes from a bad install. Ugh!

          Thanks again.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by Daveyyy
            Sorry but I forgot I had changed that before I posted. That isn't the problem. With the class named "main" the same issue comes up.
            I compile using the command prompt, as this is the way instructed in class.
            i.e. "javac Welcome.java" would be the line I use.

            However another thing I had neglected to mention was that it in fact does compile. It is when I attempt to run the program that the issue arises.

            Again the "Main" in the code I submitted is actually a fix I attempted prior to submitting.

            Also, I have tried a complete un-install and re-install. The only other forum I have gone to said that the error comes from a bad install. Ugh!

            Thanks again.
            Well, so much for giving us clear diagnostics then. It's a classpath issue: compile
            your class, check if the compiled .class file is in your current directory and run
            it like this:

            Code:
            java -cp . Welcome
            kind regards,

            Jos

            Comment

            • Nepomuk
              Recognized Expert Specialist
              • Aug 2007
              • 3111

              #7
              Originally posted by Daveyyy
              Sorry but I forgot I had changed that before I posted. That isn't the problem. With the class named "main" the same issue comes up.
              I compile using the command prompt, as this is the way instructed in class.
              i.e. "javac Welcome.java" would be the line I use.

              However another thing I had neglected to mention was that it in fact does compile. It is when I attempt to run the program that the issue arises.

              Again the "Main" in the code I submitted is actually a fix I attempted prior to submitting.

              Also, I have tried a complete un-install and re-install. The only other forum I have gone to said that the error comes from a bad install. Ugh!

              Thanks again.
              OK, let's make sure, it isn't a Problem between your chair and table.
              You have this code:
              [CODE=java]
              // Program Name: Welcome
              // Program Description: A simple program that prints a welcome statement to the console.
              // Author: ???
              // Date: 09.05.07

              public class Welcome
              {
              public static void main(String[] args)
              {
              System.out.prin t("Welcome to Java!");
              }

              }
              [/CODE]and this class is in a file called "Welcome.ja va".
              You open a console and change directory until you're in the same directory as "Welcome.ja va". Then you type
              Code:
              javac Welcome.java
              and it gives you a compilation error? And this error is:
              Code:
              Exception in thread "main" java.lang.NoClassDefFoundError: Welcome/java
              right?

              Do check, that you spell everything EXACTLY like I did here - you might run into an error because of case sensitivity. The error you posted suggests, that the compiler can't find your file.

              Just making sure:
              Code:
              javac ThisIsAbsoluteNonsense.java
              should give the same error (apart from the name of the file of course and providing, you don't have a file named "ThisIsAbsolute Nonsense.java") .

              If you followed this exactly, but the error remains, please tell us which Operating system and JDK version you are using. It might be of importance.

              Greetings,
              Nepomuk

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by nepomuk
                OK, let's make sure, it isn't a Problem between your chair and table.
                You have this code:
                [CODE=java]
                // Program Name: Welcome
                // Program Description: A simple program that prints a welcome statement to the console.
                // Author: ???
                // Date: 09.05.07

                public class Welcome
                {
                public static void main(String[] args)
                {
                System.out.prin t("Welcome to Java!");
                }

                }
                [/CODE]and this class is in a file called "Welcome.ja va".
                You open a console and change directory until you're in the same directory as "Welcome.ja va". Then you type
                Code:
                javac Welcome.java
                and it gives you a compilation error? And this error is:
                Code:
                Exception in thread "main" java.lang.NoClassDefFoundError: Welcome/java
                right?

                Do check, that you spell everything EXACTLY like I did here - you might run into an error because of case sensitivity. The error you posted suggests, that the compiler can't find your file.

                Just making sure:
                Code:
                javac ThisIsAbsoluteNonsense.java
                should give the same error (apart from the name of the file of course and providing, you don't have a file named "ThisIsAbsolute Nonsense.java") .

                If you followed this exactly, but the error remains, please tell us which Operating system and JDK version you are using. It might be of importance.

                Greetings,
                Nepomuk
                It's probably just a classpath issue.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by r035198x
                  It's probably just a classpath issue.
                  <cough/> reply #6

                  kind regards,

                  Jos ;-)

                  Comment

                  • Nepomuk
                    Recognized Expert Specialist
                    • Aug 2007
                    • 3111

                    #10
                    Originally posted by r035198x
                    It's probably just a classpath issue.
                    On the other hand, java Welcome/java (yes, that's a slash!) creates the same error as the OP has. The slash in his/her Exception does surprise me...

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Originally posted by JosAH
                      <cough/> reply #6

                      kind regards,

                      Jos ;-)
                      I'll just have another cup of that red bush tea again then.

                      Comment

                      • Nepomuk
                        Recognized Expert Specialist
                        • Aug 2007
                        • 3111

                        #12
                        Originally posted by r035198x
                        I'll just have another cup of that red bush tea again then.
                        Good idea! Can I have some? ;-)

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by nepomuk
                          Good idea! Can I have some? ;-)
                          Rose bush tea is only for the mature I'm afraid ...

                          Comment

                          • ambikasd
                            New Member
                            • Sep 2007
                            • 12

                            #14
                            Originally posted by Daveyyy
                            Hi!

                            I am not new to java by any means. But there is an error code which I have had described as a corrupt installation.

                            I am a student and everyone else in the class seems to have had no issues with their install.

                            Here is the code:

                            // Program Name: Welcome
                            // Program Description: A simple program that prints a welcome statement to the console.
                            // Author: ???
                            // Date: 09.05.07

                            public class Welcome
                            {
                            public static void Main(String[] args)
                            {
                            System.out.prin t("Welcome to Java!");
                            }

                            }

                            The error displayed is this:

                            Exception in thread "main" java.lang.NoCla ssDefFoundError : Welcome/java

                            As I said before everyone I have talked to said it is due to corrupt installation. Please help! I need Java to run properly if I am to pass. ^_^

                            Thanks!

                            Dave


                            Hi Dave,

                            Even I am a student, and i had the same problem.
                            The problem was with while setting the classpath in environment variables. In the command prompt you provide the same path where your .class files are going to be stored i.e. the classpath specified by you in the environment variables.

                            Comment

                            • Nepomuk
                              Recognized Expert Specialist
                              • Aug 2007
                              • 3111

                              #15
                              Originally posted by r035198x
                              Rose bush tea is only for the mature I'm afraid ...
                              Well, in that case I'm glad, the bush isn't rose but red! ^^

                              Comment

                              Working...