Results 1 to 7 of 7
  1. #1
    HinaKhan is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Main Method not found in class

    When I go in command prompt and run the program it says :

    Error : Main method not found in class Person, please define the main method as:
    public static void main (String[]args)




    My code in notepad is


    public class Person {

    private String firstName;
    private String lastName;
    private String address;
    private String username;

    // The constructor method

    public Person(String personFirstName , String personLastName,
    String personAddress, String personUsername)

    {

    firstName= personFirstName;
    lastName= personLastName;
    address= personAddress;
    username= personUsername;
    }
    //A method to display the state of the object on the screen

    public void displayPersonDetails()

    {
    System.out.println("Name: "+firstName+" "+lastName);
    System.out.println("Address: " +address);
    System.out.println("Username: " +username);

    }

    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,773
    Rep Power
    25

    Default Re: Main Method not found in class

    Did you try doing what the message recommended?
    The main() method is used by the java program to start the execution of the class you give it on the command line.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    HinaKhan is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Re: Main Method not found in class

    When i did what java told me it showed 26 errors . I added it in the class Person.after
    public class person {
    public static void main (String[]args)

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,773
    Rep Power
    25

    Default Re: Main Method not found in class

    Please post all the code in the class. Those two lines you posted do not show the contents of the main() method.


    Take a look at this tutorial:
    http://docs.oracle.com/javase/tutori...ion/index.html
    Last edited by Norm; 06-22-2012 at 01:26 AM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Main Method not found in class

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    5

    Default Re: Main Method not found in class

    Quote Originally Posted by HinaKhan View Post
    When i did what java told me it showed 26 errors . I added it in the class Person.after
    public class person {
    public static void main (String[]args)
    At a guess you have taken the initial error too literally and not declared the Main method correctly although I assume in the correct place.

    The following code will achieve what you require though a,b,c,d should be replaced with something more appropriate.

    Java Code:
    public static void main(String[] args)
    {
        Person p = new Person("a","b","c","d");
        p.displayPersonDetails();
    }
    Last edited by Ronin; 06-22-2012 at 03:59 PM. Reason: Code tags added ;)

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,773
    Rep Power
    25

    Default Re: Main Method not found in class

    @Ronin Please edit your post and wrap the code in code tags.
    BB Code List - Java Programming Forum
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. main method not found in class
    By eLancaster in forum New To Java
    Replies: 5
    Last Post: 02-09-2011, 09:48 AM
  2. Main Class not found
    By Draugnar in forum New To Java
    Replies: 3
    Last Post: 01-09-2010, 04:12 AM
  3. main class not found
    By abhijit in forum Networking
    Replies: 3
    Last Post: 10-01-2009, 10:05 AM
  4. No main class found error
    By jhering1986 in forum New To Java
    Replies: 17
    Last Post: 03-28-2009, 03:34 AM
  5. Replies: 4
    Last Post: 01-01-2009, 04:58 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
  •