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: Exception in thread "main" java.lang.NoSuchMethodError: main

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Exception in thread "main" java.lang.NoSuchMethodError: main

    Here I have a program called Connect4Model. Basically what the problem is that I have successfully compiled the program in TextPad. However when I run the program it throws up an Exception in thread "main" error. I fully understand what this error is, and it basically means that I'm missing the main method as shown below. However what I can see is how I can implement this. If there is a possible solution this would be great.

    Thanks


    public class Connect4Model
    {
    	Connect4Column [] columns;
    	int my_array[];
    	private int NUM_COLUMNS;
    	private int NUM_ROWS;
    	private int playerToGoNext = Connect4Column.RED_COUNTER;
     
    	Connect4Model(int numCols, int numRows)
    	{
    		columns = new Connect4Column[NUM_COLUMNS];
     
    		for (int i = 0;i < NUM_COLUMNS;i++)
    		{
    			columns[i] = new Connect4Column(NUM_ROWS);
    		}
    	}
    	int getNumCols()
    	{
    		return 0;
    	}
    	int getNumRows()
    	{
    		return 0;
    	}
    	int getNextPlayer()
    	{
    		return 0;
    	}
    	boolean go(int thisColumn)
    	{
    		if ( thisColumn < 0 ||  thisColumn >= NUM_COLUMNS)
    		{
    			return false;
    		}
     
    		else  if(my_array[thisColumn] >= NUM_ROWS)
    		{
    			return false;
    		}
    		else
    		{
    			my_array[playerToGoNext]++;
    			return true;
    		}
    	}
    	int getCounter(int thisColumn, int thisRow)
    	{
    		return 0;
    	}
    	int getNumCounters(int thisColumn)
    	{
    		if(thisColumn >= 0 && thisColumn < NUM_COLUMNS)
    		{
    			return my_array[thisColumn];
    		}
    		else
    		{
    			return 0;
    		}
    	}
     
    }


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Exception in thread "main" java.lang.NoSuchMethodError: main

    Hello dj118, welcome to the forums.

    Seeing as this thread is about Exceptions. I have moved it here: Exceptions - Java Programming Forums

    Can we see the Connect4Column class?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. The Following User Says Thank You to JavaPF For This Useful Post:

    dj118 (March 26th, 2010)

  4. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "main" java.lang.NoSuchMethodError: main

    Quote Originally Posted by JavaPF View Post
    Hello dj118, welcome to the forums.

    Seeing as this thread is about Exceptions. I have moved it here: Exceptions - Java Programming Forums

    Can we see the Connect4Column class?
    Sure you can see the Connect4Class. I've attached my code on the following link, as I don't know how to put the code within the tags. Java | public class Connect4Column { - Anonymous - 1A1PadCq - Pastebin.com

    public class Connect4Column
    {
    	private int counters[];
    	private int numCounters;
    	private int MAX_NUM_COUNTERS;
     
    	static int YELLOW_COUNTER = 1;
    	static int RED_COUNTER = 2;
     
    	public Connect4Column(int max_counters)
    	{
    		MAX_NUM_COUNTERS = max_counters;
    		counters = new int[MAX_NUM_COUNTERS];
    		numCounters = 0;
    	}
     
    	public boolean addCounter(int thisCounter)
    	{
    		if ((numCounters < MAX_NUM_COUNTERS)&&((thisCounter == 1)||(thisCounter == 2)))
    		{
    			counters[numCounters] = thisCounter;
    			numCounters++;
    			return true;
    		}
    		else
    		{
    			return false;
    		}
    	}
     
    	public int getNumCounters()
    	{
    		return numCounters;
    	}
     
    	public int getCounter(int thisRow)
    	{
    		if ((thisRow >= 0)&&(thisRow <= numCounters))
    		{
    			return counters[thisRow];
    		}
    		else
    		{
    			return 0;
    		}
    	}
    }
    I don't know if this is the correct way of putting the code into the CODE tags. But the link is also avaliable

Similar Threads

  1. Replies: 16
    Last Post: August 27th, 2010, 04:30 PM
  2. Replies: 2
    Last Post: March 23rd, 2010, 02:38 AM
  3. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  4. Please help! Exception in thread "main" java.lang.NullPointerException
    By Arutha2321 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 18th, 2009, 02:25 AM
  5. Replies: 1
    Last Post: October 25th, 2009, 12:54 PM