クラスを作成しました。その目的は、口座番号を口座番号の配列と比較し、番号が有効かどうかを返すメソッドを呼び出すことです。次のコンパイラ エラーが発生しました: Exception in thread "main" java.lang.NullPointerException at program07.AccountVal.(AccountVal.java:12) at program07.Program07.main(Program07.java:18)
これが私のクラスです
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();
どんな助けでも大歓迎です。ありがとう!