找不到主要班级,

时间:2015-03-15 16:39:26

标签: java netbeans

这是一个初学者的问题,为什么我会收到一条关于我没有任何主要课程的信息。我是一个初学者,我试图阅读有关此问题的所有其他答案。我在netbeans工作。

/**
 * @author Anders
 */
public class Main {

    public enum Valuta {  // here i assign the values i allow from the argument
        EUR,
        USD,
        RUB;

        // here i assign the conversionrates
        static final float C_EUR_TO_DKK_RATE = (float) 7.44;

        static final float C_USD_TO_DKK_RATE = (float) 5.11;

        static final float C_RUB_TO_DKK_RATE = (float) 0.156;

        static float result = 0;

        static int value = 0;


        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {

            if (args.length == 2) {
                value = Integer.parseInt(args[0]);
                String valutaIn = args[1]; //equalsIgnoreCase(null) boolean expression. How does this works??         


                Valuta enumConvert = Valuta.valueOf(valutaIn);

                switch (enumConvert) {

                    case EUR:
                        result = value * C_EUR_TO_DKK_RATE;
                        break;

                    case USD:
                        result = value * C_USD_TO_DKK_RATE;
                        break;

                    case RUB:
                        result = value * C_RUB_TO_DKK_RATE;
                        break;
                }
                System.out.println((float) value + "" + enumConvert + " converts to " + (result * 100.) / 100.0 + "Dk");
            }
            else {
                System.exit(1);
            }
        }
    }
}

1 个答案:

答案 0 :(得分:2)

方法main不在Class Main中,它在enum Valuta中。您可能想要以下内容(请注意枚举后的结束花括号):

/**
 * @author Anders
 */
public class Main {

    public enum Valuta {  // here i assign the values i allow from the argument
        EUR,
        USD,
        RUB;
    }

    // here i assign the conversionrates
    static final float C_EUR_TO_DKK_RATE = (float) 7.44;

    static final float C_USD_TO_DKK_RATE = (float) 5.11;

    static final float C_RUB_TO_DKK_RATE = (float) 0.156;

    static float result = 0;

    static int value = 0;


    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        if (args.length == 2) {
            value = Integer.parseInt(args[0]);
            String valutaIn = args[1]; //equalsIgnoreCase(null) boolean expression. How does this works??         


            Valuta enumConvert = Valuta.valueOf(valutaIn);

            switch (enumConvert) {

                case EUR:
                    result = value * C_EUR_TO_DKK_RATE;
                    break;

                case USD:
                    result = value * C_USD_TO_DKK_RATE;
                    break;

                case RUB:
                    result = value * C_RUB_TO_DKK_RATE;
                    break;
            }
            System.out.println((float) value + "" + enumConvert + " converts to " + (result * 100.) / 100.0 + "Dk");
        }
        else {
            System.exit(1);
        }
    }
}