I want to know why I am having this problem when I literally copied and pasted this section of code from one Java project to another, and didn't run into any issues in the first project.
I am attempting to display a 4x4 grid of squares.
The following exception is thrown on line 37:
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
public class DistractorTask {
private JPanel panel;
private GridBagConstraints c;
private BufferedImage squareImage;
public DistractorTask(JPanel panel){
this.panel = panel;
c = new GridBagConstraints();
displayGrid();
}
private void displayGrid() {
c.gridx = 0;
c.gridy = 0;
try {
squareImage = ImageIO.read(this.getClass().getResource("square.gif")); //line 37
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JLabel squareLabel = new JLabel(new ImageIcon(squareImage));
for(int i = 0; i < 16; i++){
c.gridx = i % 4;
c.gridy = i / 4;
panel.add(squareLabel, c);
panel.validate();
}
}
}