Problem adding JTextField to Container

Okay Experts have another java problem.

I have a program that creates textfields that will be filled with user inputs once they press a "New Users" button. This I have managed to accomplish, but I am also supposed to create a field under the buttons that contains the same infomation. The Problem I am having is creating that field and filling it with the data.

Here is the snippet of code from the actionlistener for that button.
      public void actionPerformed ( ActionEvent event )
            if ( event.getSource() == btnNewUser )
                  JPanel centerLayout = new JPanel();
                  // Prompt User for Input
                  userName = JOptionPane.showInputDialog( "Please Enter Your Name." );
                  userAge = Integer.parseInt(JOptionPane.showInputDialog( "Please Enter Your Age.") );
                  // Determine User Gender
                  userSex = JOptionPane.showInputDialog( "Please Enter you Gender.\nM for Male\nF for Female");
                  if (userSex == "F")
                        userGender = "Female";
                        userGender = "Male";
                  userHeight = Integer.parseInt( JOptionPane.showInputDialog( "Please Enter Your Height" +
                              "\nIn Inches") );
                  userWeight = Integer.parseInt( JOptionPane.showInputDialog( "Please Enter Your Weight" +
                              "\n In Pounds") );
                  // Set Text In TextFields
                  nameField.setText( userName );
                  ageField.setText( "" + userAge );
                  genderField.setText( userGender );
                  weightField.setText( "" + userWeight );
                  heightField.setText( "" + userHeight );
                        // Create User Object
                  User user = new User( userName, userAge, userWeight, userSex, userHeight );
                  String displayOutput = userName
                  JTextField display = new JTextField (displayOutput);
                  c.add( centerLayout,BorderLayout.CENTER );
                  btnOldUser.setEnabled( false );

When I run the program and click the "New User" button it gives a null pointer exception at                    ---c.add( centerLayout,BorderLayout.CENTER );---
Who is Participating?

getContentPane().add( centerLayout,BorderLayout.CENTER );
(IOW you may not have assigned 'c' - so check it)
reefcrazedAuthor Commented:
That did it CEHJ, Thanks a ton!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.