having problems with the code mentioned below. the eclipse error code is as follows ::
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at gui.PassengerGui$2.actionPerformed(PassengerGui.java:139)
Any recommendations would be very much appreciated? I have have been pulling my hair out for almost one hour trying to figure out what the problem is..
private JPanel contentPane;
private JFileChooser fileChooser;
private PassengerController controller;
private PassengerTabelPanel tabelPanel;
private JTextField nameField;
private JTextField cityField;
private JTable passengerTable;
private JRadioButton standardRadio;
private JRadioButton businessRadio;
private ButtonGroup classGroup;
private PassengerFormListener formListener;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
PassengerGui frame = new PassengerGui();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public PassengerGui() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 584, 368);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenuItem importDataItem = new JMenuItem("Import Data");
menuBar.add(importDataItem);
JMenuItem exportDataItem = new JMenuItem("Export Data");
menuBar.add(exportDataItem);
fileChooser = new JFileChooser();
fileChooser.addChoosableFileFilter(new PassengerFileFilter());
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
classGroup = new ButtonGroup();
//set up class radio
classGroup.add(standardRadio);
classGroup.add(businessRadio);
JLabel nameLabel = new JLabel("Name: ");
nameLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
nameLabel.setBounds(12, 11, 69, 31);
contentPane.add(nameLabel);
JLabel cityLabel = new JLabel("City: ");
cityLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
cityLabel.setBounds(12, 47, 69, 31);
contentPane.add(cityLabel);
JLabel lblNewLabel_2 = new JLabel("Class: ");
lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_2.setBounds(12, 89, 69, 31);
contentPane.add(lblNewLabel_2);
nameField = new JTextField();
nameField.setBounds(60, 18, 129, 20);
contentPane.add(nameField);
nameField.setColumns(10);
cityField = new JTextField();
cityField.setColumns(10);
cityField.setBounds(60, 53, 129, 20);
contentPane.add(cityField);
JRadioButton businessRadio = new JRadioButton("Business");
businessRadio.setBounds(58, 95, 109, 23);
contentPane.add(businessRadio);
JRadioButton standardRadio = new JRadioButton("Standard");
standardRadio.setBounds(60, 127, 109, 23);
contentPane.add(standardRadio);
JButton btnSubmit = new JButton("Submit");
btnSubmit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();
String city = cityField.getText();
String passengerClass = classGroup.getSelection().getActionCommand();
PassengerFormEvent ev = new PassengerFormEvent(this, name, passengerClass, city);