错误:在类MovieDatabase中找不到主要方法 [英] Error: Main method not found in class MovieDatabase

查看:89
本文介绍了错误:在类MovieDatabase中找不到主要方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:在MovieDatabase类中找不到主要方法,请将该主要方法定义为:public static void main(String [] args)或JavaFX应用程序类必须扩展javafx.application.Application

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.

推荐答案

main()方法是JVM用于开始执行任何Java程序的标准方法.主要方法称为Java应用程序的入口点,对于核心Java应用程序而言,这是正确的

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

您已经错过了.添加以下main()方法

You have missed it. Add following main() method

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

在Java编程语言中,每个应用程序都必须包含一个 签名为的主要方法:

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

public static void main(String[] args)

这篇关于错误:在类MovieDatabase中找不到主要方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆