I am having a problem with an address book program. The problem is that when I try to set the fnTextField, lNTextField, ...etc I get null in all the JTextEdits. I've went through the debugger and before the I called Edit edit = new Edit(1)
the values are in the variable, but afterwards they all say null. I'm thinking it because I'm calling "new" and it's reinitializing the values with null. If that's the problem how could I fix it?
Here is some of the code:
public class Edit
{
private JTextField fnTextEdit;
private String fn, ln, a, c, s, z, pn;
Edit()
{
//First Panel
//User enters name of contact to edit
//When user clicks editButton the "find" method is called
}
Edit(int x)
{
//Second Panel
//User edits the contact details
fnTextField = new JTextField();
//...etc
setAll();
}
public void find()
{
File file;
BufferedReader br;
String edit = lNTextField1.getText() + "& " + fNTextField1.getText()+ "& ";
String line = null, newLine = "";
try
{
file = new File(fileName);
br = new BufferedReader(new FileReader(file));
while ((line = br.readLine()) != null)
{
if(line.startsWith(edit))
{
newLine = line;
}
}
editContact = newLine.split("&");
ln=editContact[0];
fn=editContact[1];
a=editContact[2];
c=editContact[3];
s=editContact[4];
z=editContact[5];
pn=editContact[6];
}
catch(IOException e)
{
}
}
public void setAll()
{
fnTextLabel.setText(fn); //This is where I get the null pointer exception
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == editButton)
{
if(fNTextField1.getText().trim().equals("") || lNTextField1.getText().trim().equals(""))
{
message.setText("Please enter First Name and Last Name");
}
else
{
find();
//calling the new panel
Edit edit = new Edit(1);
setVisible(false);
edit.setVisible(true);
}
}
}