Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6894559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:47:52+00:00 2026-05-27T06:47:52+00:00

So basically I have this constructor for the class League : import java.util.*; public

  • 0

So basically I have this constructor for the class League:

import java.util.*;

public class League {

    private String name;
    private List<Team> teamList;

    public League(String name) {        
        List<String> teamNames = new LinkedList<String>(Company.teamList);
        Collections.shuffle(teamNames);
        teamNames.subList(0, 5);

        for(int i = 0; i < teamNames.size(); i++){
            teamList.add(new Team(teamNames.get(i)));
        }
}
}

The class Company happens to have a Set called teamList.
When I call on System.out.println(teamNames.get(i)) it shows me the content so obviously the elements of the set are there, however when I try to create a new Team object based on the elements of the list of Strings, it gives me a NullPointerException. I don’t know why is that? Help?

Here is the code for the Team class in case you need it:

import java.util.HashMap;
import java.util.Map;


public class Team {

    protected Map<Integer, Player> teamPlayerMap;
    private String teamName;

    public Team(String name) {
        teamPlayerMap = new HashMap<Integer, Player>();
        teamName = name;
    }

    public String getTeamName() {
        return teamName;
    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:47:53+00:00Added an answer on May 27, 2026 at 6:47 am

    I think the problem is here:

    private List<Team> teamList;
    
    public League(String name) {        
        // etc...
    
        for(int i = 0; i < teamNames.size(); i++) {
            teamList.add(new Team(teamNames.get(i))); // This will throw!
        }
    }
    

    You need to create an instance of a class that implements List<Team> and assign it to teamList. You haven’t done this so it will throw a NullPointerException when you call teamList.add(...).

    The fix is to write this instead:

    private List<Team> teamList = new ArrayList<Team>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a component like this public class MyComponent { public MyComponent(string name)
I have a custom UIComponent that is basically just this: public class WhiteboardUIComponent extends
I basically have: Public Class Job: MyBaseClass { public virtual string JobInformation {get;set;} ...
I have Java classes like this: public class Config { public Config1 getConfigOpt1(); public
I have this script which basically toggles a bgColor class on and off so
import org.springframework.beans.factory.annotation.Autowired; class MyService { @Autowired private DependencyOne dependencyOne; @Autowired private DependencyTwo dependencyTwo; public
So I have declared a vector in my class header like this: ... private:
Good afternoon all, I have a class which looks like this: public class Grapheme
I have this error that is keeping me from moving forward. I basically have
Well basically I have this script that takes a long time to execute and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.