java.lang.NullPointerException "main"线程中的异常错误一直指向 get 方法


private static void printReport(Country[] country) {
System.out.printf("%-25s%-16s%-10s%-18s%-17s%-14sn",
"Name", "Code", "Capitol", "Population", "GDP", "HappinessRank");
System.out.print("------------------------------------------------------------------------------------------------------");
System.out.println("");
for (Country b  : country) {
System.out.printf("%-26s%-17s%-7s%10d%8s%-18s%7dn",
b.getName(), b.getCode(), b.getCapitol(), b.getPopulation(), b.getGDP(), b.getHappinessRank());
}           
}

大家好!Java编程新手,但我被卡住了,我试图查找如何修复它,但没有成功。

我在寻找什么?它一直指向b.getName((,b.getCode((等。

更多代码:

public static void main(String[] args) throws FileNotFoundException {
int maxCountries = 156;
Country[] countries = new Country[maxCountries];

String csvName = "Countries1.csv";
Scanner scanner = new Scanner(new File(csvName));
Scanner csvScan = scanner.useDelimiter("[,n]"); {
System.out.println("Enter the File Name:"+csvName);
System.out.println("Amount of Countries Read:"+maxCountries);

在运行循环之前,请验证您的输入是否有效。此函数只有一个参数要检查,因此请检查country是否不为 NULL

最新更新