-1
private static void printReport(Country[] country) {

        System.out.printf("%-25s%-16s%-10s%-18s%-17s%-14s\n",
                "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%7d\n",
                    b.getName(), b.getCode(), b.getCapitol(), b.getPopulation(), b.getGDP(), b.getHappinessRank());
        }           
    }

Hey everyone! New to java programming,but I am stuck, I tried looking up how to fix it with no success.

What am I looking for? it keeps pointing at the b.getName(), b.getCode(), etc.

More of the code:

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);
evalency9
  • 1
  • 2
  • 2
    Your code is incomplete, but `b` is probably `NULL`. The error is somewhere else. We can't help you unless you produce a [mcve]. – giusti Sep 15 '19 at 22:00

1 Answers1

0

Before running the loop verify your input is valid. This function have only one parameter to check, so check if country is not NULL

Simson
  • 3,373
  • 2
  • 24
  • 38