title: Java: Filling a JComboBox with objects
body: <p>I'm trying to fill a jComboBox with objects. I have it working in one class, but in this class it's giving a <code>NullPointerException</code> but the code is almost the same. What am I missing here?</p>
  
  <p>The code I'm using to fill the comboboxes:</p>
  
  <p>I have translated every variable to English and removed some unnescessary stuff. I hope it's more clear for you guys now:</p>
  
  <pre><code>package unive.billing.boundary.clientmanager.frames;
  
  import unive.billing.control.ClientsManager;
  import unive.billing.control.InsuranceManager;
  
  /**
   *
   * @author Forza
   */
  
  public class ClientFrame extends javax.swing.JFrame {
  
  /**
   * Creates new form AddClientGUI
   */
  private ClientsManager clientmanager;
  private InsuranceManager insurancemanager;
  
  public ClientFrame() {
      initComponents();
      clientmanager = new ClientsManager();
      clientmanager.printList();
      updateComboBoxCompany();
      updateComboBoxInsurance();
  }
  
  private ClientsManager clientmanager;
  private InsuranceManager insurancemanager;
  
  public ClientFrame() {
      initComponents();
      clientmanager = new ClientsManager();
      clientmanager.printList();
      updateComboBoxCompany();
      updateComboBoxInsurance();
  }
  
  public void updateComboBoxCompany() 
  {
      for (Object object : insurancemanager.getCompanyNames()) 
      {
          companyComboBox.addItem(object);
      }   
  }
  
  public void updateComboBoxInsurance() 
  {
      for (Object object : insurancemanager.getPolicyNames()) 
      {
          insuranceComboBox.addItem(object);
      }   
  }
  </code></pre>
  
  <p>Here are the methods used:</p>
  
  <pre><code>public Object[] getCompanyNames() 
  {
      ArrayList&lt;String&gt; cnames = new ArrayList&lt;String&gt;();
      for (InsurancesCompany company : insurancecompanyList) 
      {
          cnames.add(company.getCompanyName());
      }
      return cnames.toArray();
  }
  
  public Object[] getPolicyNames() 
  {
      ArrayList&lt;String&gt; vnames = new ArrayList&lt;String&gt;();
      for (Insurance insurance : insuranceList) 
      {
          vnames.add(insurance.getPolicyName());
      }
      return vnames.toArray();
  }
  </code></pre>
  
  <p>This is how my lists are initialized:</p>
  
  <pre><code>public class InsuranceManager {
  
  private String insurancePath;
  private String insurancecompanyenPath;
  private static List&lt;InsurancesCompany&gt; insurancecompanyList;
  private static List&lt;Insurance&gt; insuranceList;
  private Insurance currentInsurance;
  
  public InsuranceManager() {
      insurancecompanyenPath = "Files/company.txt";
      insurancePath = "Files/insurance.txt";
      insuranceList = new List&lt;&gt;();
  }
  
  public void createNewList() 
  {
      insurancecompanyList = new List&lt;&gt;();
      System.out.println("Creates list");
  }
  
  public Object[] getCompanyNames() 
  {
      ArrayList&lt;String&gt; cnames = new ArrayList&lt;String&gt;();
      for (InsurancesCompany company : insurancecompanyList) 
      {
          cnames.add(company.getCompanyName());
      }
      return cnames.toArray();
  }
  
  public Object[] getPolicyNames() 
  {
      ArrayList&lt;String&gt; vnames = new ArrayList&lt;String&gt;();
      for (Insurance insurance : insuranceList) 
      {
          vnames.add(insurance.getPolicyName());
      }
      return vnames.toArray();
  }
  </code></pre>
  
  <p>Edit: Here's the MainGUI which calls createNewList (maakLijstAan)</p>
  
  <pre><code>private ClientsManager clientsmanager;
  private BillingManager billingmanager;
  private InsuranceManager insurancemanager;            
  
  public MainGUI() {
      clientsmanager = new ClientsManager();  
      clientsmanager.CreateNewList();
      insurancemanager = new InsuranceManager();
      insurancemanager.CreateNewList();
      insurancemanager.loadInsuranceCompanyList();
      initComponents();
      jMenuItem1.setText("Save clients"); 
      jMenuItem2.setText("Load clients"); 
      jMenuItem3.setText("Exit");
  }
  </code></pre>