Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: CMD line is owning me

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    34
    My Mood
    Inspired
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default CMD line is owning me

    Ok everyone - I believe that I am having Path issues with my compiler. I have compiled and run code many times. In this case it is the basic helloworldapp in the tutorial. I do not know what to make of this error. I have checked and rechecked my Path and think I am ok. For whatever reason my code still does not compile...


    C:\Java>javac HelloWorldApp.java
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/M
    ain
    Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: com.sun.tools.javac.Main. Program will exit.

    Is there a place where you can research java errors?

    Any help is great!

    Thanks.

    ch103


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,235
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: CMD line is owning me

    This looks to be a CLASSPATH issue rather than an issue with the PATH - if it were a PATH issue, javac would not be recognized. Make sure the file is in the same directory as the directory you are currently in, and that all classes you have written are in the appropriate location relative to the main class. If your java file specifies a package, be sure you are located in the root directory of the package.

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Location
    philadelphia
    Posts
    8
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: CMD line is owning me

    When you are running java in C:\Java,

    you have to make sure that your HelloWorldApp.java must in the path like this
    C:\Java\HelloWorldApp.java ( if the package of HelloWorldApp.java is null)
    or
    C:\Java\aaa\bbb\ccc\ddd\HelloWorldApp.java ( if the package of HelloWorldApp.java is like "package aaa.bbb.ccc.ddd;"
    Acoolme is an Online Marketing Software Platform And Social Community

  4. #4
    Member
    Join Date
    Oct 2011
    Posts
    42
    My Mood
    Sneaky
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: CMD line is owning me

    I was having this problem too, even though I was adding the location to the class path, it was not pickiong it up. Try running the app with the command

    java -cp C:\myFolder\ HelloWorld

  5. #5
    Member
    Join Date
    Aug 2011
    Posts
    34
    My Mood
    Inspired
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: CMD line is owning me

    Ok everyone, I am still having issues with this and am really at a crossroads on this. I am still getting the same error message as I originally posted.

    Note - my Path variable has been set properly
    Note - my ClassPath Variable has been set properly as well.

    Any help would most certainly be appreciated. I tried to copy and paste it into google but no luck.

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,465
    My Mood
    Grumpy
    Thanks
    0
    Thanked 158 Times in 149 Posts

    Default Re: CMD line is owning me

    It is simple.

    On the command line change directory to the directory where your HelloWorldApp.java file is located. Confirm this by using the 'dir' command. If you are in the correct directory you compile your program with
    javac HelloWorldApp.java
    Make sure you get the spelling and capitalisation correct. If it works and no errors are shown then a HelloWorldApp.class file has been created. You then run your program with
    java HelloWorldApp
    Take special notice of the two commands and when you do and do not use file extensions.
    Improving the world one idiot at a time!

  7. #7
    Member
    Join Date
    Aug 2011
    Posts
    34
    My Mood
    Inspired
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: CMD line is owning me

    thank you for your help Junky but it did not work. here is one think that I think is contributing to my problem.

    I have jre6 in Program Files (x86)\Java 64 bit

    I have jdk1.6.0_29 in Program Files\Java 64 bit

    I am not sure why I am having these issues. I mean, it should just compile already, lol.

  8. #8
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,465
    My Mood
    Grumpy
    Thanks
    0
    Thanked 158 Times in 149 Posts

    Default Re: CMD line is owning me

    Is your code correct? Your java class and the file must have the same name.
    Post the result of the dir command.
    Improving the world one idiot at a time!

Similar Threads

  1. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  2. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  3. Reading a file line by line using the Scanner class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  4. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM