Results 1 to 11 of 11
- 02-21-2011, 01:42 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
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.
- 02-21-2011, 01:44 PM #2
How are you trying to compile and run this? It looks like you're trying to run main, when you want to be running HelloWorldApp.
Recommended reading: "Hello World!" for Microsoft Windows (The Java™ Tutorials > Getting Started > The "Hello World!" Application)How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-21-2011, 01:51 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
I have been compiling the program as
javac HelloWorldApp.java
- 02-21-2011, 01:54 PM #4
And how are you trying to run it?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-21-2011, 01:55 PM #5
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
Iam trying to run it as
java HelloWorldApp
- 02-21-2011, 01:57 PM #6
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
by the by If I don't compile it I'll never be able o run it .right?
- 02-21-2011, 02:15 PM #7
Are you sure that's how you're compiling it? Are you in the correct directory? Your error message does not match up to what you're saying.
But you're correct, you must compile a .java file before you can use the .class file.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-21-2011, 02:20 PM #8
Follow the link Kevin has posted above. That explains almost everything to run your first java program.
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 03-15-2011, 08:59 PM #9
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
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.
-
Ofcourse there is nothing wrong with the code, it is something else but I think I know what the problem is. When you saved the Java file in notepad, did you save the coding type as UNICODE or ANSI? If it is Unicode that would explain your error. Save it as ANSI and it'll be fine.
- 03-16-2011, 05:43 AM #11
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
First Java Program-Has Errors-simple GUI
By cc11rocks in forum New To JavaReplies: 1Last Post: 01-04-2011, 12:15 AM -
Help with compiling HelloWorldApp
By JonBrad in forum New To JavaReplies: 13Last Post: 01-09-2010, 04:04 PM -
Errors with simple program... PLEASE HELP ME!!!
By maxpower1000sa in forum New To JavaReplies: 6Last Post: 05-03-2009, 11:55 PM -
Debuggin help - simple program non-static method errors
By RR_QQ in forum New To JavaReplies: 5Last Post: 02-04-2009, 01:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks