我的一种方法有问题。请记住,我在大学里学习 Java,所以我可能跟不上简单的事情。下面是一种用于添加表达式的方法。我遇到的问题是在x = x.substring.(1, x.length() - 1);我得到一个异常的地方发现的:
Exception in thread "main" java.lang.NullPointerException
我不知道这意味着什么和/或如何解决它。如果你能指出我正确的方向,那就太好了。谢谢。
public static int adder(String x){
    int total = 0;
    x = x.substring(1, x.length() - 1);
    sopln(x);
    String[] nums = x.split("\\+");
    for(int i = 0; i < nums.length; ++i){
        if(nums[i].charAt(0) == ' ' || nums[i].charAt(nums[i].length()-1) == ' '){
            sopln("ERROR: Excess whitespace identified.");
            nums[i] = nums[i].trim();
        }
        nums[i] = nums[i].replaceAll(" ", "");
        if(nums[i].charAt(0) == '-')
            total -= Integer.parseInt(nums[i]);
        else
            total += Integer.parseInt(nums[i]);
    }
    return total;
}