Java 我不知道';我不知道为什么我的代码赢了';跑不动

Java 我不知道';我不知道为什么我的代码赢了';跑不动,java,Java,我正在做一个计算器程序,我把所有的东西都设置好了,很早就开始工作了,但是在我添加了一个方法之后,当我在调试模式下运行时,Eclipse说我的主方法有一个错误。我不知道它为什么跑不动 我得到的错误是: 线程“main”java.lang中出现异常。错误:未解决的编译问题: at com.molotuff.main.Calculator.main(Calculator.java:13) 这是我的密码: package com.molotuff.main; import java.util.Arr

我正在做一个计算器程序,我把所有的东西都设置好了,很早就开始工作了,但是在我添加了一个方法之后,当我在调试模式下运行时,Eclipse说我的主方法有一个错误。我不知道它为什么跑不动

我得到的错误是: 线程“main”java.lang中出现异常。错误:未解决的编译问题:

at com.molotuff.main.Calculator.main(Calculator.java:13)
这是我的密码:

package com.molotuff.main;

import java.util.ArrayList;
import java.util.Scanner;

public class Calculator {
    private static Scanner reader = new Scanner(System.in);
    private static boolean running = true;
    private static boolean calcRunning = true;
    private static String command;
    private static ArrayList<Integer> nums = new ArrayList<Integer>();

    public static void main(String[] args) {
        System.out.println("*****************************");
        System.out.println("* Welcome to The Calculator *");
        System.out.println("*****************************");
        menu("help");

        while(running) {
            System.out.println("Enter a command:");
            command = reader.nextLine();
            menu(command);
            if(command.equalsIgnoreCase("quit")) {
                running = false;
            }
            if(command.equalsIgnoreCase("add")) {
                getNums();
                int answer = Calculations.sum(nums);
                System.out.println("The sum is: " + answer);
            }
        }
    }

    public static void menu(String command) {
        if(command.equalsIgnoreCase("help")) {
        System.out.println("Commands: ");
        System.out.println("Quit");
        System.out.println("Help");
        System.out.println("Add");
        System.out.println("Subtract");
        System.out.println("Divide");
        System.out.println("Multiply");
        System.out.println("Type help [command] for more info on that command");
        }
        if(command.equalsIgnoreCase("help quit")) {
            System.out.println("Quit: quits the program.");
        }
        if(command.equalsIgnoreCase("help help")) {
            System.out.println("Help: prints the help menu.");
        }
        if(command.equalsIgnoreCase("help add")) {
            System.out.println("Add: takes numbers inputed and adds them together.");
        }
        if(command.equalsIgnoreCase("help Subtract")) {
            System.out.println("Subtract: takes a set of numbers and subtracts     them \n (note: "
                    + "subtracts in this order [first num entered] - [second num entered] "
                    + "etc.)");
        }
        if(command.equalsIgnoreCase("help multiply")) {
            System.out.println("Add: takes numbers inputed and multiplies them     together.");
        }
        if(command.equalsIgnoreCase("help divide")) {
            System.out.println("Subtract: takes a set of numbers and divides     them \n (note: "
                    + "divides in this order [first num entered] / [second num     entered] " 
                    + "etc.)");
        }

    }
}

    public static void getNums() {
        while(calcRunning) {
            String userInput = reader.nextLine();
            int userNums;
            if(userInput.isEmpty()) {
                calcRunning = false;
            } else {
                userNums = Integer.parseInt(userInput);
                nums.add(userNums);
            }
        }
    }
}
package com.molotuff.main;
导入java.util.ArrayList;
导入java.util.Scanner;
公共类计算器{
专用静态扫描仪阅读器=新扫描仪(System.in);
私有静态布尔运行=true;
私有静态布尔calcRunning=true;
私有静态字符串命令;
私有静态ArrayList nums=新ArrayList();
公共静态void main(字符串[]args){
System.out.println(“*************************************”);
System.out.println(“*欢迎使用计算器*”);
System.out.println(“*************************************”);
菜单(“帮助”);
(跑步时){
System.out.println(“输入命令:”);
command=reader.nextLine();
菜单(命令);
if(command.equalsIgnoreCase(“quit”)){
运行=错误;
}
if(command.equalsIgnoreCase(“add”)){
getNums();
int answer=计算值。总和(nums);
System.out.println(“总和为:“+答案”);
}
}
}
公共静态无效菜单(字符串命令){
if(command.equalsIgnoreCase(“help”)){
System.out.println(“命令:”);
System.out.println(“退出”);
System.out.println(“帮助”);
系统输出打印项次(“添加”);
系统输出打印项次(“减法”);
系统输出打印项次(“分割”);
System.out.println(“乘法”);
System.out.println(“有关该命令的更多信息,请键入help[command”);
}
if(command.equalsIgnoreCase(“帮助退出”)){
System.out.println(“退出:退出程序”);
}
if(command.equalsIgnoreCase(“help”)){
System.out.println(“帮助:打印帮助菜单”);
}
if(command.equalsIgnoreCase(“帮助添加”)){
System.out.println(“Add:获取输入的数字并将它们相加。”);
}
if(command.equalsIgnoreCase(“帮助减法”)){
System.out.println(“减法:获取一组数字并进行减法运算\n(注意:
+“按此顺序减去[first num entered]-[second num entered]。”
+“等”);
}
if(command.equalsIgnoreCase(“帮助乘法”)){
System.out.println(“Add:获取输入的数字并将它们相乘。”);
}
if(command.equalsIgnoreCase(“help divide”)){
System.out.println(“减法:获取一组数字并将它们相除\n(注意:
+“按此顺序除[输入的第一个数值]/[输入的第二个数值]”
+“等”);
}
}
}
公共静态void getNums(){
同时(calcRunning){
字符串userInput=reader.nextLine();
int userNums;
if(userInput.isEmpty()){
calcRunning=假;
}否则{
userNums=Integer.parseInt(userInput);
添加(userNums);
}
}
}
}

getNums()
方法之前移除一个结束括号
这就是为什么
getNums()
没有包含在类主体中并给出错误的原因。

Eclipse说我的主方法中有一个错误-什么错误?这是编译器错误吗?运行时错误?在getNums方法之前有一个额外的右大括号('}')。这是它告诉我的线程“main”java.lang中的异常。错误:未解决的编译问题:在com.molotuff.main.Calculator.main(Calculator.java:13)上,方法
static void getNums()
超出了类范围。你需要删除它上面的多余的}。谢谢,我不确定我怎么会错过它,因为我想我已经多次通过括号了。。同样奇怪的是,Eclipse在我编写代码时没有将其显示为错误。