You probably have not initialized allComp
and it's null
.
JComponent allComp[] = new JComponent[MAX_COMPONENTS];
Anyway, it is advisable to use a List
instead of an array if you don't know beforehand the number of components.
List<JComponent> allComp = new ArrayList<>();
allComp.add(new JComboBox());
allComp.add(new JButton());
allComp.add(new JMonthChooser());