无法找出我的Java代码为什么不起作用

问题描述 投票:0回答:1

我正在尝试使用Java制作油漆分配器模拟原型控制台应用程序。到处搜索,似乎无法找出为什么此代码行不通。我用netbeans。我要用此代码执行的操作是显示菜单,要求用户输入,当用户输入数字时,它会从菜单中选择该选项,然后,一旦菜单生效,我就需要开始使这些选项起作用。任何帮助表示赞赏,谢谢。到目前为止,我的代码如下所示。

    package paintdispensersimulation;

    import java.util.Scanner;
    /**
    *
    * @author Kris Newton (M2124910)
    */
    public class PaintDispenserSimulation   //
    {                                       //Open Public Class 
    public static void main(String[] args)  //
    {                                       //Start Main
        Scanner in = new Scanner (System.in);   //
        int option;                             //
        boolean quit = false;                   //Declare variables                                  
        do  //
        {   //Start Do
            System.out.println("Please Make a selection:");                     //
            System.out.println("[1] Process New Job(Decimal Values)");          //
            System.out.println("[2] Process New Job(RGB Hexadecimal Values)");  //
            System.out.println("[3] Calibrate Dispenser");                      //
            System.out.println("[4] Display Summary Of Jobs");                  //
            System.out.println("[0] Exit");                                     //Print Menu
            option = in.nextInt();  //Declare User Input
            switch (option)         //Declare Switch
            {                       //Start Switch            
                case 1:                                                                     //If Option = 1
                    System.out.println("You Chose To: Process New Job(Decimal Values)");    //Print            
                    break;                                                                  //Break
                case 2:                                                                             //If Option = 2
                    System.out.println("You Chose To: Process New Job(RGB Hexadecimal Values)");    //Print  
                    break;                                                                          //Break                                                                          
                case 3:                                                                     //If Option = 3
                    System.out.println("You Chose To: Calibrate Dispenser");                //Print 
                    break;                                                                  //Break
                case 4:                                                                             //If Option = 4
                    System.out.println("You Chose To: Display Summary Of Jobs");                    //Print
                    break;                                                                          //Break
                case 0:                                                                     //If Option = 0
                    quit = true;                                                            //Quit                                                            
                    break;                                                                  //Break
                default:                                                                            //If Option Invalid
                    System.out.println("Selection Invalid: Please enter a valid selection.");       //Print           
            }   //End Switch           
        }   //End Do 
        while (!quit);                              //While Quit = True
        System.out.println("You Chose To: Exit");   //Print
    }   //End Main    
}   //End Public Class

这是我尝试运行时收到的消息。

run:
java.lang.VerifyError: Constructor must call super() or this() before return in method paintdispensersimulation.PaintDispenserSimulation.<init>()V at offset 0
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
    at java.lang.Class.getMethod0(Class.java:2685)
    at java.lang.Class.getMethod(Class.java:1620)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
java menu switch-statement
1个回答
0
投票

我能够在Eclipse中运行此代码。

VerifyError可能意味着字节码无效。

基本上,这是一个编译器错误,或者如果类文件已损坏

尝试使用不同的JDK版本和不同的机器进行编译。

© www.soinside.com 2019 - 2024. All rights reserved.