Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



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

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 02-01-2010
Member
 
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.
Reply With Quote
  #2  
Old 02-01-2010
Member
 
Join Date: Feb 2008
Posts: 1,845
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.?
Reply With Quote
  #3  
Old 02-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,947
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.
Reply With Quote
  #4  
Old 02-01-2010
Member
 
Join Date: May 2008
Posts: 2,007
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.
Reply With Quote
  #5  
Old 02-01-2010
Member
 
Join Date: May 2008
Posts: 2,290
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.
Reply With Quote
  #6  
Old 02-01-2010
Member
 
Join Date: May 2008
Posts: 2,382
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Getting an ERROR when trying to compile the Correct Code!?"
Thread Thread Starter Forum Replies Last Post
How to Correct the "Compile error in hidden module: ThisWorkbook" in Microsoft Excel Lanka Boy MS Office Support 3 04-01-2014 03:27 PM
Can I compile code on AMD Opteron and run on AMD Xeon? Ga.One Motherboard Processor & RAM 5 11-12-2011 11:02 AM
Unable to compile managed C++ code by using the VC 7.0 fanish-war Software Development 4 25-06-2011 09:46 PM
How to get vlc source code and compile in windows xp Bhukkam Windows Software 2 24-04-2011 12:13 AM
Unable to compile and execute code spuff Software Development 5 24-12-2009 12:56 PM


All times are GMT +5.5. The time now is 04:23 AM.