ok so I'm coding my own version of a GUI based addition calculator. and I've come upon an error . but when I run it , it gives a null pointer exception at the line where I marked in the code and i know null pointer means there is no value for a certain string or integer but this one here does have a value , if someone knows why pls tell me , thanks in advance!
`public class Main implements ActionListener {
private static JFrame frame;
private static JPanel panel;
private static JLabel label;
private static JButton button;
private static JTextField fnumField;
private static JTextField snumField;
private static JLabel answer;
private static JLabel fnum;
private static JLabel snum;
private static String c;
public static void main(String[] args) {
frame = new JFrame();
panel = new JPanel();
frame.setSize(350, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
panel.setLayout(null);
JLabel fnum = new JLabel("1st number:");
fnum.setBounds(10, 20, 80, 25);
panel.add(fnum);
JTextField fnumField = new JTextField();
fnumField.setBounds(100, 20, 165, 25);
panel.add(fnumField);
JLabel snum = new JLabel("2nd number:");
snum.setBounds(10, 50, 80, 25);
panel.add(snum);
JTextField snumField = new JTextField();
snumField.setBounds(100, 50, 165, 25);
panel.add(snumField);
button = new JButton("ADD");
button.setBounds(10, 80, 80, 25);
button.addActionListener(new Main ());
panel.add(button);
JLabel answer = new JLabel("");
answer.setBounds(10, 100, 300, 25);
panel.add(answer);
answer.setText(c);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String a = fnumField.getText(); <---------- NULL POINTER
String b = snumField.getText();
String c = (a+b);
}
}
`