2

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.

Michelle
  • 61
  • 1
  • 2
  • 6

4 Answers4

1

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)
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
0

As the error suggests, if its non FX project, just define something like:

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

Or else change you class definition so it extends Application, something like:

public class MovieDatabase extends Application
SMA
  • 36,381
  • 8
  • 49
  • 73
0

To invoke any application JVM need main() method, and which should have following access specifiers and modifiers,

public static void main(String args[])

public - It should be accessible to all
static - JVM not able to create instance of your class so method should be static
void - method not returning anything

For each java application main method is entry point, so your application should have atleast one main method to start execution of application.

atish shimpi
  • 4,873
  • 2
  • 32
  • 50
0

It's because you have forgot to add the main method. The error clearly says:

please define the main method as: public static void main(String[] args)

So add the main:

public static void main(String[] args) {
    MovieDatabase m = new MovieDatabase("Your File Path");
    m.print();
}
Leo
  • 5,017
  • 6
  • 32
  • 55