Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Null pointer exception when adding team to list of teams: Soccer League Organizer

Can anyone see why there is a null pointer exception? Here is what happens:

Select an option: create
What is the team name: iouou
What is the coach name: team coach
Exception in thread "main" java.lang.NullPointerException
at com.teamtreehouse.LeagueView.run(LeagueView.java:69)
at LeagueManager.main(LeagueManager.java:15)

```public class LeagueView {

private BufferedReader mReader; private int count; private int index; //private Players players; private Player[] players;

private Map<String, String> mMenu; private Team mTeam; private Teams mTeams;

public LeagueView(Player[] players){ this.players = players;

```         case "create":
              mTeam = promptNewTeam();
              mTeams.addTeam(mTeam);
            System.out.printf("The team %s has been created with %s as coach. %n%n", mTeam.getTeamName(), mTeam.getCoachName());
            break;```

Line 69: mTeams.addTeam(mTeam);
Lines 14 and 15 from LeagueManager:
 LeagueView view = new LeagueView(players);
    view.run();

1 Answer

The question is now answered. I was missing the instantiation mTeams = new Teams();