程序没有为Java编译我错过了什么

时间:2018-04-15 12:49:22

标签: java netbeans

package freshjuice;


class FreshJuice {

    enum FreshJuiceSize { SMALL, MEDIUM, LARGE }
        FreshJuiceSize size;
    }


}

public class FreshJuiceTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        FreshJuice juice = new FreshJuice();
        juice.size = FreshJuice.FreshJuiceSize.MEDIUM ;
        System.out.println("Size: " + juice.size);
        // TODO code application logic here
    }

}

这是我收到的错误消息:

Error: Main method not found in class freshjuice.FreshJuice, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
C:\Users\TheGODMasterDu\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 2 seconds)

2 个答案:

答案 0 :(得分:2)

您的文件必须被称为FreshJuiceTest.java,因为这是您的主要方法所在的类。

答案 1 :(得分:2)

您的文件名为FreshJuice.java,但不包含main()
简而言之,在你的第一堂课中寻找main()的netbeans

将文件名更改为FreshJuiceTest.java或更换类的代码,并将FreshJuice.java定义为public并从第二类中删除public