# No Main Method Found?

• 02-26-2013, 10:42 PM
connorlm3
No Main Method Found?
I missed class two days last week. My class did a program together and I asked the teacher what I need to do. He said contents of it could be on the test so I need to get it from another student and see how it works. I asked a student to email me it, when he did i copied and pasted it into netbeans, went to run it, and keep getting a no main method found error? The main method has a static before it, so it isnt because of that. So what is the problem?

Code:

``` package mat2670; import java.util.*; public class MagicSquare {     // The n/sidelength value of the magicsquare     private static int magicNumber;     // Array of integers holding the user's inputs      private static int[] inputs;     // Double array containing the magic square     private static int[][] magicSquare;     private static int count = 0;     public static void main(int args) {                 magicNumber = args;         magicSquare = new int[args][args];         inputs = new int[(int) Math.pow(Double.valueOf(args), 2)];         }     /**     *     * @return the magic constant m using the formula m = n * (n^2 + 1) / 2 ex.     * n = 3 m = 3 (3^2 +1) 2 m = 15     */     private static int computeMagicConstant() {                 return (int) (magicNumber * (Math.pow(magicNumber, 2) + 1) / 2);     }     /**     *     * @return true if the sum of rows equals magic constant     */     private static boolean checkRows() {         for (int row = 0; row < magicSquare.length; row++) {             int tempSum = 0;             for (int col = 0; col < magicSquare.length; col++) {                 tempSum += magicSquare[row][col];             }             if (tempSum != computeMagicConstant()) {                 return false;             }         }         return true;     }     /**     *     * @return true if the sum of columns equals magic constant     */     private static boolean checkColumns() {         for (int col = 0; col < magicSquare.length; col++) {             int tempSum = 0;             for (int row = 0; row < magicSquare.length; row++) {                 tempSum += magicSquare[row][col];             }             if (tempSum != computeMagicConstant()) {                 return false;             }         }         return true;     }     /**     *     * @return true if sum of diagonals equals magic constant     */     private boolean checkDiagonals() {         // Check bottom left to top right         for (int cornerRow = getMagicSquare().length - 1; cornerRow >= 0; cornerRow--) {             int tempSum = 0;             for (int cornerColumn = 0; cornerColumn < getMagicSquare().length; cornerColumn++) {                 tempSum += magicSquare[cornerRow][cornerColumn];             }             if (tempSum != computeMagicConstant()) {                 return false;             }         }         // Check bottom right to top left         for (int cornerRow = getMagicSquare().length - 1; cornerRow >= 0; cornerRow--) {             int tempSum = 0;             for (int cornerColumn = getMagicSquare().length - 1; cornerColumn >= 0; cornerColumn--) {                 tempSum += magicSquare[cornerRow][cornerColumn];             }             if (tempSum != computeMagicConstant()) {                 return false;             }         }         return true;     }     /**     * Checks if userinput is the full range of numbers from n to n^2 Checks if     * number of inputs equals n^2     *     * @return     */     public static boolean checkInput() {         // Convert the array to a Set of integers. Duplicates will be eliminated          Set<Integer> setMagicSquare = new HashSet<Integer>();         for (int i = 0; i < inputs.length; i++) {             setMagicSquare.add(inputs[i]);         }         // Check if the number of values equals n^2         if (setMagicSquare.size() != Math.pow(magicNumber, 2)) {             return false;         }         // Check if all values from 1 to n^2 is present         for (int i = 1; i <= Math.pow(magicNumber, 2); i++) {             if (!setMagicSquare.contains(i)) {                 return false;             }         }         return true;     }     /**     *     * @param i a value typed in by the user     */     public static void addInt(int i) {         inputs[count] = i;         count++;     }     /**     *     * @return true if the numbers form a magicsquare     */     public boolean isMagic() {         fillMagicSquare();         return checkInput() && checkRows()                 && checkColumns()                 && checkDiagonals();     }     /**     *     * @return an instance of the magicsquare     */     public int[][] getMagicSquare() {         return this.magicSquare;     }     /**     * Creates a magicsquare array     */     private static void fillMagicSquare() {         int counter = 0;         for (int row = 0; row < magicNumber; row++) {             for (int col = 0; col < magicNumber; col++) {                 magicSquare[row][col] = inputs[counter];                 counter++;             }         }     } }```
• 02-26-2013, 11:37 PM
Norm
Re: No Main Method Found?
Please post the full text of the error message. It has important information.
• 02-26-2013, 11:54 PM
jim829
Re: No Main Method Found?
Your signature for the main method is wrong. It must be
Code:

```public static void main(String [] args) { ... ... }```
Any numeric values passed to main must be converted to numeric types.

Jim
• 02-27-2013, 12:25 AM
connorlm3
Re: No Main Method Found?
Ooh ok, can i change args into an int with Integer.ParseInt?
• 02-27-2013, 12:35 AM
jim829
Re: No Main Method Found?
Yes.

Jim