Results 1 to 11 of 11
  1. #1
    sripriya is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default 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.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default

    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!

  3. #3
    sripriya is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    I have been compiling the program as

    javac HelloWorldApp.java

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default

    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!

  5. #5
    sripriya is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    Iam trying to run it as

    java HelloWorldApp

  6. #6
    sripriya is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    by the by If I don't compile it I'll never be able o run it .right?

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default

    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!

  8. #8
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Follow the link Kevin has posted above. That explains almost everything to run your first java program.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  9. #9
    fishnfever is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Default 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.

  10. #10
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    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.

  11. #11
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default comment problem

    your code is right

    except you forgot to give comment here
    **
    * The HelloWorldApp class implements an application that
    * simply prints "Hello World!" to standard output.
    */
    at the end .

Similar Threads

  1. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  2. First Java Program-Has Errors-simple GUI
    By cc11rocks in forum New To Java
    Replies: 1
    Last Post: 01-04-2011, 12:15 AM
  3. Help with compiling HelloWorldApp
    By JonBrad in forum New To Java
    Replies: 13
    Last Post: 01-09-2010, 04:04 PM
  4. Errors with simple program... PLEASE HELP ME!!!
    By maxpower1000sa in forum New To Java
    Replies: 6
    Last Post: 05-03-2009, 11:55 PM
  5. Replies: 5
    Last Post: 02-04-2009, 01:20 AM

Posting Permissions

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