我创建了一个类,它的对象是将帐号与帐号数组进行比较,并调用一个方法来返回一个数字是否有效。我收到以下编译器错误:program07.Program07.main(Program07.java:18) 的 program07.AccountVal.(AccountVal.java:12) 的线程“main”java.lang.NullPointerException 中的异常
这是我的课
package program07;
public class AccountVal
{
private String[] accountNums;
private String newAccount;
public AccountVal()
{
accountNums[0] = "5658845";
accountNums[1] = "8080152";
accountNums[2] = "1005231";
accountNums[3] = "4520125";
accountNums[4] = "4562555";
accountNums[5] = "6545231";
accountNums[6] = "7895122";
accountNums[7] = "5552012";
accountNums[8] = "3852085";
accountNums[9] = "8777541";
accountNums[10] = "5050552";
accountNums[11] = "7576651";
accountNums[12] = "8451277";
accountNums[13] = "7825877";
accountNums[14] = "7881200";
accountNums[15] = "1302850";
accountNums[16] = "1250255";
accountNums[17] = "4581002";
newAccount = "";
}
public void setAccountNums(String[] acc)
{
accountNums = acc;
}
public void setNewAccount(String newAcc)
{
newAccount = newAcc;
}
public String[] getAccountNums()
{
return accountNums;
}
public String getNewAccount()
{
return newAccount;
}
public boolean AccountValidation(String newAccount)
{
boolean test = false;
for (int i = 0; i < 18; i++)
{
if(newAccount == accountNums[i])
{
test = true;
}
}
return test;
}
}
错误从程序中引用的行是我声明对象时:
AccountVal test = new AccountVal();
任何帮助将不胜感激。谢谢你!