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

  • SEARCH
  • Home
  • 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 8674593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:44:50+00:00 2026-06-12T19:44:50+00:00

I’m trying to fill a jComboBox with objects. I have it working in one

  • 0

I’m trying to fill a jComboBox with objects. I have it working in one class, but in this class it’s giving a NullPointerException but the code is almost the same. What am I missing here?

The code I’m using to fill the comboboxes:

I have translated every variable to English and removed some unnescessary stuff. I hope it’s more clear for you guys now:

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);
    }   
}

Here are the methods used:

public Object[] getCompanyNames() 
{
    ArrayList<String> cnames = new ArrayList<String>();
    for (InsurancesCompany company : insurancecompanyList) 
    {
        cnames.add(company.getCompanyName());
    }
    return cnames.toArray();
}

public Object[] getPolicyNames() 
{
    ArrayList<String> vnames = new ArrayList<String>();
    for (Insurance insurance : insuranceList) 
    {
        vnames.add(insurance.getPolicyName());
    }
    return vnames.toArray();
}

This is how my lists are initialized:

public class InsuranceManager {

private String insurancePath;
private String insurancecompanyenPath;
private static List<InsurancesCompany> insurancecompanyList;
private static List<Insurance> insuranceList;
private Insurance currentInsurance;

public InsuranceManager() {
    insurancecompanyenPath = "Files/company.txt";
    insurancePath = "Files/insurance.txt";
    insuranceList = new List<>();
}

public void createNewList() 
{
    insurancecompanyList = new List<>();
    System.out.println("Creates list");
}

public Object[] getCompanyNames() 
{
    ArrayList<String> cnames = new ArrayList<String>();
    for (InsurancesCompany company : insurancecompanyList) 
    {
        cnames.add(company.getCompanyName());
    }
    return cnames.toArray();
}

public Object[] getPolicyNames() 
{
    ArrayList<String> vnames = new ArrayList<String>();
    for (Insurance insurance : insuranceList) 
    {
        vnames.add(insurance.getPolicyName());
    }
    return vnames.toArray();
}

Edit: Here’s the MainGUI which calls createNewList (maakLijstAan)

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");
}
  • 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-06-12T19:44:52+00:00Added an answer on June 12, 2026 at 7:44 pm

    You never initialize verzekeringBeheer, therefore you get a NullPointerException when you try to invoke methods on that variable.

    You should have somewhere in your constructor, something like this:

    verzekeringbeheer = new VerzekeringBeheer();
    

    Also, try to avoid making your code coupled with other parts of your code. For example:

    public VerzekeringBeheer() {
        ...
        //verzekeringmaatschappijLijst is never initialized!!!
    }
    
    public void maakLijstAan() 
    {
        verzekeringmaatschappijLijst = new Lijst<>();
        System.out.println("Maak lijst aan");
    }
    
    public Object[] getMaatschappijNamen() 
    {
        ArrayList<String> mnamen = new ArrayList<String>();
        // Here you use verzekeringmaatschappijLijst without checking that is not null!!!
        for (VerzekeringsMaatschappij maatschappij : verzekeringmaatschappijLijst) 
        {
            mnamen.add(maatschappij.getMaatschappijNaam());
        }
        return mnamen.toArray();
    }
    

    If nobody calls maakLijstAan, you will get a NullPointerException in getMaatschappijNamen. Try to avoid code that is so dependent of external code, in order to run without problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

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.