errors while compiling a simple HelloWorldApp java program
hello!Iam new to java and while compiling a simple java program I get the following errors:
Exception in thread "main" java.lang.noclassdeffounderror com/sun/tools/javac/main
and
could not find the main class:com.sun.tools.javac.main
my code is as follows:
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
public class HelloWorldApp {
public static void main(String[] args){
System.out.println("Hello World!"); // Display the string.
}
}
I will be greatful to anyone who can help me with this problem.
Adding javac to your system variables
I too was having trouble getting my first HelloWorld program to run. I kept getting "javac not recognized as an internal or external command . . .". I knew the problem was with my environment variables. I searched the web and just about every one of them would tell you to edit or add the string into your system variables. Well, if you're new to the world of java or programming in general this information leaves you with the feeling of the cup is half full, as far as 'how to'.
I am definately in the newbie group. I tried countless permutations on adding to the system variables with the same results. I noticed I already had a 'path' variable and thought I needed to add a new one . . . WRONG. This is the variable you edit. I was thinking of the word 'edit' to literally as changing (replacing) the value string. Well, don't forget that adding to the string is editting it also.
What led me to this was I noticed another application in the 'path' variables value string. I scrolled across the value line and noticed it wasn't the only application in the list and that each applications value was separated by a ";".
Here's what I had in my path value string:
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoo t%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowe rShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\QuickTime\QTSystem\
In short, all you need to do is add your compiler to the list: ..\java\jdk1.6.0_24\bin;
Make sure you have the full path and YOUR version of jdk.
It was a great lesson, I learned so much before even getting started into java.
Summary:
Right click computer, select properties, advanced system settings. Sytem Properties box should appear. Make sure advanced tab is selected and click the Environment Variables button. Look for the 'path' variable and select edit. Add your compiler's path and make sure you have it ";" separated.