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

Thread: Main Method Error

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    1
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Main Method Error

    Here's my issue.

    I have been coding simple java program in eclipse classic. It never gave me any issues with the Main Method. Here is my code.

    import javax.swing.*;
    public class main {
    public static void main(String args[]){
    JFrame window = new JFrame("CraftBukkit Starter");
    window.setLocationRelativeTo(null);
    window.setVisible(true);
    JLabel label = new JLabel("");
    label.setText("Welcome!");
    }
    }


    There. Now in the bold spot it says: This method has a constructor name.
    When I fix it it removes void and then makes the whole main method an error.
    Please help me.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Main Method Error

    Probably because you've named your class main. It probably thinks you are trying to make a constructor or something. Don't name your class main.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Main Method Error

    classes should start with a capital letter not lowercase....rename your file Main.java instead of main.java and make the first main (public class Main) with a capital M instead of lowercase

  4. #4
    Junior Member
    Join Date
    Nov 2012
    Location
    Kolkata, India
    Posts
    8
    My Mood
    Cool
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Main Method Error

    @derekxec and @aussiemcgr i agree with you.

    class names are started with capital letters. but, most probably a bigger problem is that "main" is a JAVA reserved keyword. It is better not to use it as a class name.

  5. #5
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Main Method Error

    a bigger problem is that "main" is a JAVA reserved keyword
    It isn't a keyword according to the JLS 3.9. Keywords.

Similar Threads

  1. Error: Main method not found! Please help!
    By adnan.alvee in forum What's Wrong With My Code?
    Replies: 12
    Last Post: March 11th, 2013, 07:03 PM
  2. Replies: 3
    Last Post: October 31st, 2011, 12:42 AM
  3. How to call a value from a different method to main
    By CrimsonFlash in forum What's Wrong With My Code?
    Replies: 13
    Last Post: October 22nd, 2011, 06:29 PM
  4. How do I call a method from the main method?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 19th, 2011, 08:37 PM
  5. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM