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

Thread: Don't understand the error

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Don't understand the error

    Can anyone help me figure this out? I wrote the following code for my programming class.

    package weekthreeassignments;

    /**
    *
    * @author fred
    */

    public class Odds {
    public static void main(String[] args) {
    int product = 1;
    for (int i = 1; i <= 15; i++)
    if (i % 2 == 1) {
    product *= i;
    }
    System.out.println("Product of the odd integers from 1 to 15 is: " + product);
    }
    }


    When I run the code I get the following error and how to fix it, but if you read the "Please define" part, I did define it that way. Why am I still erroring?


    Error: Main method not found in class weekthreeassignments.Odds, please define the main method as:
    public static void main(String[] args)
    or a JavaFX application class must extend javafx.application.Application
    C:\Users\fred\AppData\Local\NetBeans\Cache\10.0\ex ecutor-snippets\run.xml:111: The following error occurred while executing this line:
    C:\Users\fred\AppData\Local\NetBeans\Cache\10.0\ex ecutor-snippets\run.xml:68: Java returned: 1
    BUILD FAILED (total time: 0 seconds)

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Don't understand the error

    The posted code compiles and executes without any errors for me. Are you sure that is the code you are testing with?
    Could there be another version somewhere?

    How are you executing the code?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2018
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Don't understand the error

    That is my code. I don't know how but for some reason the class was not inside the Source folder inside the package. Somehow the package got created someplace else. Once I moved it to the correct folder, it executed just fine for me.

Similar Threads

  1. [SOLVED] I have a NullPointerException error that I dont understand
    By LukeR in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 14th, 2013, 06:15 PM
  2. JButton, JTable error not understand.
    By kpat in forum AWT / Java Swing
    Replies: 1
    Last Post: April 11th, 2012, 02:37 PM
  3. My code has error when its run....I dont understand what's wrong of it.
    By jacky@~ in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 11th, 2011, 07:48 AM
  4. I can't understand the error.
    By Shivam24 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 21st, 2011, 01:56 PM
  5. I can''t understand this error
    By ragingdemon in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 8th, 2011, 06:07 PM