i seem to have a rather peculiar issue with my overloaded constructors
in the default constructor AutoFleetServicesMain()
i have
listModel = new DefaultListModel();
list = new JList(listModel);
and in the overloaded constructor AutoFleetServicesMain(int i)
i have
listModel.addElement(dbh.findAll());
according to my output, the default constructor is called before the overloaded one, so i see no reason why listModel is null
although if i add listModel = new DefaultListModel(); to the overloaded constructor, it will run without erroring but i still don’t get a list?
Any ideas for what i could do?
It sounds like you want to chain your constructors, but that doesn’t happen automatically. Try adding the following statement to the beginning of your
AutoFleetServicesMain(int)constructor:This will call the default constructor before the subsequent logic. See this post for more examples of constructor chaining: How do I call one constructor from another in Java?