0

I'm using Java Eclipse 2019.3, and no matter what I try I can't get this program to run. It's giving me the 'Selection does not contain a main type' error message.

Things I've tried:

  • using the formatting 'clean up' option
  • changing the class name to match that of the file
  • changing the class name to match that of the file and the folder (file is currently named Main.java, class on code is Main)
  • updating and restarting Eclipse as a whole
  • capitalizing and uncapitalizing 'main'
  • running from the 'Run as' option and clicking 'Java application' manually
  • creating an entirely new project, copy-and-pasting the code into a new class, and attempting to run it again

Please help, I have no idea what's happening even after checking all the other answers on this forum and others. This is the code:

package australianvoting295;

import java.util.Scanner; 

public class Main {

   static void australianvoting295 (int[][] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Number of cases: ");
        int numberofcases = in.nextInt();
        System.out.println("");
        System.out.println("Number of candidates");
        int numberofcandidates = in.nextInt();
        if (numberofcandidates <= 20) {
            int numberofballotoptions = in.nextInt();
            if (numberofballotoptions <= 1000) {
                enterCandidateNames(numberofcandidates);
            }
        }
    }

    static void enterCandidateNames(int numberofcandidates) {
        Scanner in = new Scanner(System.in);
        String[] numberofcandidatesarray = new String[numberofcandidates];
        int counter = 0;
        while (in.hasNext()) {
            while (counter < numberofcandidates) {
                System.out.println("Enter candidate name:");
                String candidatename = in.next();
                numberofcandidatesarray[numberofcandidates] = candidatename;
                counter++;

            }
        }
    }
}
  • ...you know you need a main method to run the program right? – beastlyCoder Mar 02 '20 at 03:42
  • 1
    The error is informing you that you must include a main *method*: include the line `public static void main(String args[]) {}` in your class in order for it to compile, and then add whatever statements into that method you would like for the program to run, such as making a call to `enterCandidateNames` via `enterCandidateNames(5);`, for example – ajc2000 Mar 02 '20 at 03:43
  • Does this answer your question? [Error: Selection does not contain a main type](https://stackoverflow.com/questions/16225177/error-selection-does-not-contain-a-main-type) – smac89 Mar 02 '20 at 04:04

1 Answers1

0

You are trying too many things to resolve a rather simple error. As Eclipse tells you, if you try to run a class, it should contain a method with the signature

public static void main(String[] args) {
}

Go through this Hello world tutorial for more understanding.

VHS
  • 9,534
  • 3
  • 19
  • 43