Error: Main method not found in class MovieDatabase

31,070

main() method in Java is an standard method which is used by JVM to start execution of any Java program. main method is referred as entry point of Java application which is true in case of core java application

You have missed it. Add following main() method

public static void main(String[] args) {
    MovieDatabase db = new MovieDatabase("file/path/goes/here");
    db.print();
}

In the Java programming language, every application must contain a main method whose signature is:

public static void main(String[] args)
Share:
31,070
Michelle
Author by

Michelle

Updated on February 19, 2020

Comments

  • Michelle
    Michelle over 4 years

    Error: Main method not found in class MovieDatabase, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

    import java.io.FileInputStream;
    import java.util.Scanner;
    import java.util.Arrays;
    
    public class MovieDatabase {
        private int[] analysis;
    
        //creating the contructor
        public MovieDatabase(String file){
            analysis = new int[2015];
    
            this.load(file);
        }
            //uses the load(String file) method from downstairs to do all of the work
    
    
        public void  load(String file){
            Scanner theScanner = null;
    
            try{
                //inputing the into the scanner
                theScanner = new Scanner(new FileInputStream(file));
            }
            catch(Exception ex){ 
                ex.printStackTrace();
            }
            // as long as the scanner has another line 
            while(theScanner.hasNextLine())
            {
                String Line = theScanner.nextLine();
                //make an array called split and allocated different elements based on a seperation of ##
                String split[] = Line.split("##");
                int year = Integer.valueOf(split[1]); 
                analysis[year] ++;
            }   
    
        }
    
        //print out the array in the synchronous format
        public void print(){
            System.out.printf("%1$-30s %2$10s %3$10s %4$10s ", "Year", "Occurances", "", "");
            //go through the array
            for (int i =0;i < analysis.length ;i++ ) {
                if(analysis[i] >0){
                    for (int j =i;j < analysis.length ;i++ ){
                        System.out.printf("%1$-30s %2$10s %3$10s %4$10s ", j, analysis[j], "", "");
                    }
                }   
            }
        }
    } 
    

    How do I fix this error message? Ive read other similar questions but just say to make the classes public. Mine are public.