The exception is thrown at this line: frame.add(panel);

Remove the JFrame and JPanel from the constructor. Basically what you do there, is to redeclare them locally, and the actual frame/panel...