【发布时间】:2017-06-16 16:48:05
【问题描述】:
我正在运行这个 JUint 测试方法,并且在运行时遇到异常 NullPointerException。这个异常怎么处理?
@Test
public void testDivision1() {
System.out.println("testDivision");`
Operation instance = new Operation(100, 2, null);
int res = instance.calculate();
assertEquals(50, res);
}
【问题讨论】:
-
Operation长什么样子? -
公共类操作 { private final int firstOperand; private final int secondOperand;私有最终 EnumOp 运算符;公共操作(int firstOperand,int secondOperand,EnumOp 运算符){ this.firstOperand = firstOperand; this.secondOperand = secondOperand; this.operator = 运算符; } public int calculate() { return operator.calculate(firstOperand, secondOperand); } }
-
请使用该代码更新您的问题。
标签: exception-handling nullpointerexception