I have a class Catalogue
to store info about it. Here i had just use two methods:
public void setCataName(String n)
{cataName = n;}
public String getCataName()
{return cataName;}
This is the code for my JFrame:
public class AddCataFrame extends JFrame
{
JLabel lname;
JTextField tname;
Catalogue catalogue;
AddCataFrame()
{
super("Add New Catalogue");
setLayout(new FlowLayout());
lname = new JLabel("Name:", SwingConstants.LEFT);
tname = new JTextField(15);
textListener t = new textListener();
tname.addActionListener(t);
add(lname);
add(tname);
}
class textListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
//get the name from the textField after entered by user
//then set it to the name of catalogue.
//This is the place give me NullPointerException error.
catalogue.setCataName(tname.getText());
JOptionPane.showMessageDialog(null,catalogue.getCataName());
}
}
}
I cannot figure it out why give me a NullPointerException. Please help me.