Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at SwingTutorialPackage.SamplePanel.createEntryFields (SamplePanel.java:124)
at SwingTutorialPackage.SamplePanel.<init>(SamplePane l.java:27)
at SwingTutorialPackage.SamplePanel.createAndShowGUI( SamplePanel.java:150)
at SwingTutorialPackage.SamplePanel.access$0(SamplePa nel.java:144)
at SwingTutorialPackage.SamplePanel$2.run(SamplePanel .java:163)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
getting this error help me out
below is the code for the generated error
package SwingTutorialPackage;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;

public class SamplePanel extends JPanel implements ActionListener,FocusListener

{
JTextField Name,JDBCDriver,JDBCURL,ServerAddress,Database,Use rname,Password;
Font regularFont, italicFont;
final static int GAP = 1;

public SamplePanel() {
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
JPanel testpanel = new JPanel(){
//Don't allow us to stretch vertically.
public Dimension getMaximumSize() {
Dimension pref = getPreferredSize();
return new Dimension(Integer.MAX_VALUE,
pref.height);
}
};;
testpanel.setLayout(new BoxLayout(testpanel,
BoxLayout.PAGE_AXIS));
testpanel.add(createEntryFields());
testpanel.add(createButtons());}

protected JComponent createButtons() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.TRAILING));

JButton button = new JButton("Wizard");
button.addActionListener(this);
button.setActionCommand("wizard");
panel.add(button);

button = new JButton("Test");
button.addActionListener(this);
button.setActionCommand("Test");
panel.add(button);

button = new JButton("Save");
button.addActionListener(this);
button.setActionCommand("Save");
panel.add(button);

button = new JButton("Cancel");
button.addActionListener(this);
button.setActionCommand("Cancel");
panel.add(button);

panel.setBorder(BorderFactory.createEmptyBorder(0, 0,
GAP-5, GAP-5));
return panel;
}

public void actionPerformed(ActionEvent e) {
if ("wizard".equals(e.getActionCommand()))
{
Name.setText("");
}else {
JDBCDriver.setText("");
}
}



public void focusGained(FocusEvent e) {
Component c = e.getComponent();
if(c instanceof JTextField) {
((JTextField)c).selectAll();
}
}
//Needed for FocusListener interface.
public void focusLost(FocusEvent e) { } //ignore


protected JComponent createEntryFields() {
JPanel panel = new JPanel(new SpringLayout());

String[] labelStrings = {
"Name: ",
"JDBC Driver: ",
"JDBC URL: ",
"Server Address: ",
"Database:",
"Username:",
"Password:",

};
JLabel[] labels = new JLabel[labelStrings.length];
JComponent[] fields = new JComponent[labelStrings.length];
int fieldNum = 0;

//Create the text field and set it up.
Name = new JTextField();
Name.setColumns(20);
fields[fieldNum++] = Name;

JDBCDriver = new JTextField();
JDBCDriver.setColumns(20);
fields[fieldNum++] = JDBCDriver;

JDBCURL = new JTextField();
JDBCURL.setColumns(20);
fields[fieldNum++] = JDBCURL;

ServerAddress = new JTextField();
ServerAddress.setColumns(20);
fields[fieldNum++] = ServerAddress;

Database = new JTextField();
Database.setColumns(20);
fields[fieldNum++] = Database;

//Associate label/field pairs, add everything,
//and lay it out.
for (int i = 0; i < labelStrings.length; i++) {
labels[i] = new JLabel(labelStrings[i],
JLabel.TRAILING);
labels[i].setLabelFor(fields[i]);
panel.add(labels[i]);
panel.add(fields[i]);

//Add listeners to each field.
JTextField tf = null;
tf=(JTextField)fields[i];
tf.addActionListener(this);
tf.addFocusListener(this);
}
SpringUtilities.makeCompactGrid(panel,
labelStrings.length, 2,
GAP, GAP, //init x,y
GAP, GAP/2);//xpad, ypad
return panel;
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event dispatch thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("WelcomePage");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

//Add contents to the window.
frame.add(new SamplePanel());

//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
//Turn off metal's use of bold fonts
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});}




}