我知道什么是空指针异常,但我不明白为什么我会得到它。
以下是引发错误的行:
IUserAction pinResponse = ATM.getUserResponse("Please enter your 4-digit PIN.", ActionType.STRING);
IUserAction是一个公共接口类,ActionType是一个枚举。
这很奇怪,因为我被添加了代码,这条线被赋予了我,我认为它应该可以工作,而我不熟悉Java,我不是新的面向对象编程,所以我不确定为什么这不起作用。
这里有更多代码:
package com.atm;
import com.atm.IUserAction.ActionType;
/**
* The ATM implementation class.
*
* @author mshields
*
*/
public class AtmImpl {
private static final IAtmHelper ATM = AtmUtils.getAtmHelper();
/**
* This method is invoked when a bank card is inserted into the ATM. The card
* is ejected immediately upon completion of this method, which represents the
* user's ATM session.
*
* @param args
* the bank card number is the only argument.
*/
public static void main(String args[]) {
IUserAction pinResponse = ATM.getUserResponse("Please enter your 4-digit PIN.", ActionType.STRING);
if (ActionType.STRING.equals(pinResponse.getActionType())
&& ATM.verifyPIN(args[0], pinResponse.getStringEntry()))
{
// todo: ...
继承IUserAction的开始
package com.atm;
import java.math.BigDecimal;
/**
* Interface that defines a user action at the ATM.
*
* @author mshields
*
*/
public interface IUserAction {
public enum ActionType {
/**
* Indicates that the user typed a series of characters or digits (for
* example, a PIN).
*/
STRING,
和ATM
package com.atm;
import java.math.BigDecimal;
import java.util.List;
import com.atm.IUserAction.ActionType;
/**
* Interface that defines ATM utility methods.
*
* @author mshields
*
*/
public interface IAtmHelper {