因此,GiveTaxChart方法应该采用收入数组,以升序排列,然后使用每个收入通过payableTax方法接收的税值填充taxArr,但是即使payableTax方法已经过测试并且确实有效,Im当我使用GiveTaxChart方法并输入合理的值时,仍然得到NullpointerException。 我的方法有什么明显的问题吗?还是应该找别的地方?
public static void giveTaxChart(int[] incomeArray) {
Arrays.sort(incomeArray);
for (int i = 0; i < incomeArray.length; i++) {
for (int j = 0; j < incomeArray.length; j++) {
taxArr[j] = TaxCalculator.payableTax(incomeArray[i]);
draw(i * 20, (i * 20) + 1, taxArr[j]);
}
draw(i * 20, i * 20, incomeArray[i]);
}
}
这是完整的错误消息:
Exception in thread "main" java.lang.NullPointerException
at com.company.Entities.TaxChart.giveTaxChart(TaxChart.java:36)
at com.company.Main.main(Main.java:21)
这是主要包含的内容:
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int income = in.nextInt();
System.out.println("Tax payable is" + " " + TaxCalculator.payableTax(income) + " " + "£");
int numberOfIncomes = in.nextInt();
int [] incomeArray = new int[numberOfIncomes];
for (int i = 0;i < numberOfIncomes ; i++ ){
incomeArray[i] = in.nextInt();
}
TaxChart.giveTaxChart(incomeArray);
}
这是taxArr的声明:
private static Integer[] taxArr;