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 main void (Static [] args)
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;
		}
	}

}

In a separate class or in one of the ones you already have, put that method:

public static void main(String [] args) {
   // instantiate objects and call their methods
}

Inside it you will put the code that you want executed. Then you will run the file that has the main method inside:
> java MainClass

Also in the constructor you do not use the arguments and the variables you do use (NUM_COLUMNS) have value 0. Shouldn't you be assigning the arguments to the local variables?

This article has been dead for over six months. Start a new discussion instead.