I am trying to build an application for which i need to display number of check boxes that depends on the number of input.
For example: If user inputs 100, so i will create 100 check boxes.
Currently in example i am trying to make an array of JCheckboxes of fixed length. But it is giving Null Pointer Exception.
I need to store the value of check boxes because i will perform action accordingly whether a particular check box is selected or not after the user click Button.
JCheckBox [] chk=new JCheckBox[10];
for(int i=0;i<10;i++)
{
gbc.fill=GridBagConstraints.HORIZONTAL;
gbc.gridx=0;
gbc.gridy=i+1;
JCheckBox xp=chk[i];
jp.add(xp,gbc);
}
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at UI.<init>(UI.java:93)