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 7 of 7

Thread: Code Error

  1. #1
    Junior Member
    Join Date
    Nov 2017
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Code Error

    l keep getting a code error when processing javac in the DOS command prompt using jdk-9. I can't find any syntax errors.
    The process stops with error listed after class Moonweight. Here is the code. Any ideas would be appreciated.
    I'm just learning from a library book.

    code = java

    /* A program to compute your effective weight on the moon.
    Program called "Moonweight.java".
    */

    class Moonweight {
    public static void main(String args[]) {
    double eweight; // weight in pounds on earth
    double mweight; // weight in pounds on the moon

    eweight = 230; // weight on earth
    mweight = eweight * .17; // calculate effective weight on moon

    System.out.println("weight on earth is" + eweight);
    System.out.println("weight on moon is" + mweight);
    }
    }
    /code

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Code Error

    What is the error you getting ?
    Whatever you are, be a good one

  3. #3
    Junior Member
    Join Date
    Nov 2017
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Code Error

    Quote Originally Posted by John Joe View Post
    What is the error you getting ?
    code = java (result of processing javac)

    class Moonweight {
    ^
    1 error


    code = java (result of processing java Moonweight.java)
    Moonweight.java is located under \bin the same as javac & java commands.

    /*Error: Could not find or load main class Moonweight.java
    Caused by: java.lang.ClassNotFoundException: Moonweight.java
    */
    Last edited by eng60; November 11th, 2017 at 01:47 PM. Reason: Additional information on error.

  4. #4
    Junior Member
    Join Date
    Nov 2017
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Code Error

    I updated with additional error message.
    It is probably so simple...I just don't see it.
    Thanks for reviewing.

  5. #5
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Code Error

    Can you show us how you run your java class ? What command you used ?
    Whatever you are, be a good one

  6. #6
    Junior Member
    Join Date
    Nov 2017
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Code Error

    At the DOS command prompt the directory is set for where the javac file and Moonweight.java file is located under \bin.
    I run javac Moonweight.java and get the 1 error message pointing to class Moonweight {.
    This was version jdk-9.

    Since then I have uninstalled Java version 9 and installed version 8. I will try again and see what the results will be.
    Thank you!

  7. #7
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Code Error

    Don't forget to update here
    Whatever you are, be a good one

Similar Threads

  1. Error in code
    By LivioRazlo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 10th, 2014, 08:05 PM
  2. Replies: 3
    Last Post: May 8th, 2014, 06:25 AM
  3. Replies: 4
    Last Post: January 24th, 2013, 11:20 AM
  4. Replies: 7
    Last Post: January 24th, 2013, 10:41 AM
  5. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM