Results 1 to 6 of 6

Thread: Getting an ERROR when trying to compile the Correct Code!?

  1. #1
    Join Date
    Aug 2006
    Posts
    221

    Getting an ERROR when trying to compile the Correct Code!?

    I am very new to the Java. I am getting fed up when trying to run the file called Hello.java. The text is exact as I described below :
    public class Hello
    {
    public static void main(String[] args)
    {
    System.out.println("Hello, World!" );
    System.out.println("It Worked!" );
    }
    }
    According to me this is the correct code. Since I am getting the error in the basic program, I am certainly feeling embarrassed. The error says "java.lang.NoClassDefFoundError", which I am not able to understand. Have I made any mistake in my code.?? Intelligent Guys out there Please help me..
    AMD Sempron 2800+ @ 2Ghz
    Asus A7V8X-LA
    120Gb Seagate barracuda 7200Rpm Ultra-ATA 100
    Elixir 512mb DDR Pc3200 (Soon 1Gb)
    Club 3D Radeon 9600 256Mb
    Lite-On Cd & Dvd writer combo
    IDE-Dvd drive
    400w Psu
    Windows Xp Pro Sp2
    Advent Wireless Mouse & Keyboard.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,856

    Re: Getting an ERROR when trying to compile the Correct Code!?

    The error "java.lang.NoClassDefFoundError" comes mostly when you do the wrong coding. But seeing the basic code of Hello.java, I don't think that there is some error in your code. I have not compiled that exact code yet, but the logic seems to be correct. I will definitely check and will let you know. Anyways have you tried to compile some other program.?? Are you getting the same error while compiling the another program.?

  3. #3
    Join Date
    Apr 2008
    Posts
    1,949

    Re: Getting an ERROR when trying to compile the Correct Code!?

    The code that you mentioned, I just pasted that in my notepad. Then I compiled it from the command line and to my surprise it ran fine without giving any error. I think that there is something wrong with your Java setup. Which version of Java are you using.?? There is absolutely no error in the Hello.java that you have mentioned. You should try using the same code after reinstalling the Java setup and definitely it will work.

  4. #4
    Join Date
    May 2008
    Posts
    2,015

    Re: Getting an ERROR when trying to compile the Correct Code!?

    The program code
    public class Hello
    {
    public static void main(String[] args)
    {
    System.out.println("Hello, World!");
    System.out.println("It Worked!");
    }
    }
    worked flawless on my system. Now even I think that there should be something wrong in your setup or the Library or Bin folders. Try to reinstall the java setup and make sure that you are using the latest version of it.

  5. #5
    Join Date
    May 2008
    Posts
    2,302

    Re: Getting an ERROR when trying to compile the Correct Code!?

    I think that since your Code is correct (assuming the proper setup), it looks that there is an issue of classpath. When you are trying to compile the Hello.java (javac), I would recommend you to use the full path of the file. Suppose the file is located in C:\MyClasses\Hello.java then use the command javac C:\MyClasses\Hello.java . Doing this will create Hello.class in the same directory as Hello.java . Then while executing use the command :
    java -classpath C:\MyClasses Hello
    Doing this can fix the issue.

  6. #6
    Join Date
    May 2008
    Posts
    2,393

    Re: Getting an ERROR when trying to compile the Correct Code!?

    If the JVM that you installed is working properly, then there is definitely the classpath issue. Even I think that the code is correct. I have not compiled it but looking at it I can say that it is error-less. Many times there are small errors that can't be observed. So try to compile another program and if you are getting the same error then its definitely the setup. Otherwise if the other program is running then try to search the error in the code.

Similar Threads

  1. Replies: 3
    Last Post: 04-01-2014, 03:27 PM
  2. Can I compile code on AMD Opteron and run on AMD Xeon?
    By Ga.One in forum Motherboard Processor & RAM
    Replies: 5
    Last Post: 11-12-2011, 11:02 AM
  3. Unable to compile managed C++ code by using the VC 7.0
    By fanish-war in forum Software Development
    Replies: 4
    Last Post: 25-06-2011, 09:46 PM
  4. How to get vlc source code and compile in windows xp
    By Bhukkam in forum Windows Software
    Replies: 2
    Last Post: 24-04-2011, 12:13 AM
  5. Unable to compile and execute code
    By spuff in forum Software Development
    Replies: 5
    Last Post: 24-12-2009, 12:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •