Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By Junky

Thread: Help me I get this error: Error: Main method not found in class Position

  1. #1
    lo2
    lo2 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Help me I get this error: Error: Main method not found in class Position

    Hi there I am totally new to Java, and I have tried to create this very simple class:

    Where I have a postion and then I want to be able to get the column and row of that position...

    Java Code:
    public class Position
    {
    	private int column;
    
    	private int row;
    
    	public Position()
    	{
    		column = 4;
    		row = 3;
    	}
    	public int getColumn()
    	{
    		return column;
    	}
    	public int getRow()
    	{
    		return row;
    	}
    	
    }
    But I get this error message:

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

    I have pretty much copied an example from my textbook so I am not really sure why I get this error, so could you please help me out?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Help me I get this error: Error: Main method not found in class Position

    The JVM can't find a main( ... ) method in that class (and neither can I); the JVM needs that method to start the entire show. I you copied that class from somewhere, that class wasn't meant to be used as a starting point of a program.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    lo2
    lo2 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Re: Help me I get this error: Error: Main method not found in class Position

    Ok but then you can create a Main class that calls these other classes and thereby brings them to use, right?
    (I have to write more than one class)

    And could you perhaps give me a tip on that would look?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help me I get this error: Error: Main method not found in class Position

    Even better than a tip, we'll give you an entire tutorial: The Really Big Index

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Help me I get this error: Error: Main method not found in class Position

    Quote Originally Posted by Darkzombies View Post
    Although really, I would probably do it like this:
    I wouldn't. Declaring everything as static goes against OO principles.

  6. #6
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Re: Help me I get this error: Error: Main method not found in class Position

    But I'm still a noob too, and If I don't it won't compile (╯□)╯︵ ┻━┻

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Help me I get this error: Error: Main method not found in class Position

    Then perhaps you should gain a better understanding of what static means before offering bad advice.
    Fubarable likes this.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help me I get this error: Error: Main method not found in class Position

    I have to agree with Junky, and in fact since your advice is potentially misleading to a newbie, I've deleted your post (and will delete this post as well). Let's stick to giving advice on things we're familiar with.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Help me I get this error: Error: Main method not found in class Position

    Quote Originally Posted by Fubarable View Post
    Let's stick to giving advice on things we're familiar with.
    Can there be a 'Grolsch' forum section then?

    kindest regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. main method not found error in class . wat s the error?
    By kirankumaragnihotram in forum New To Java
    Replies: 10
    Last Post: 06-29-2012, 12:26 PM
  2. Main Method not found in class
    By HinaKhan in forum New To Java
    Replies: 6
    Last Post: 06-22-2012, 03:34 PM
  3. <No main classes found> Error
    By hersman in forum NetBeans
    Replies: 2
    Last Post: 04-23-2011, 02:08 AM
  4. main method not found in class
    By eLancaster in forum New To Java
    Replies: 5
    Last Post: 02-09-2011, 09:48 AM
  5. No main class found error
    By jhering1986 in forum New To Java
    Replies: 17
    Last Post: 03-28-2009, 03:34 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
  •