title: nullpointerException on a JTextfield with Text in it
body: <p>So you guys said you don't have enough information to help me. I'm sorry it's the first time I  asked a question in such a forum and I didn't work a long time with Java.</p>
  
  <p>So here's my whole code, there could be a lots of faults but I'm glad if you help me to solve them and say me how to do better Java Programming in all. </p>
  
  <p><strong>Main Class:</strong></p>
  
  <pre><code>public class Main {
    public static void main(String[] args) {
      new Main().top();
    }
  
    void top() {
  
      GUI g = new GUI();
  
  
    }  
  }
  </code></pre>
  
  <p><strong>Class GUI:</strong></p>
  
  <pre><code>import java.awt.event.ActionListener;
  import java.text.SimpleDateFormat;
  import javax.swing.*;
  
  public class GUI {
  
  JFrame frame;
  JPanel panel;
  static JLabel label;
  static JLabel username_bezeichnung;
  static JLabel vorname_bezeichnung;
  static JLabel nachname_bezeichnung;
  static JLabel geburtstag_bezeichnung;
  static JLabel email_bezeichnung;
  static JLabel passwort_bezeichnung;
  static JButton registrieren;
  static JButton login;
  static JButton registrierenBestätigen;
  static JTextField username;
  static JTextField vorname;
  static JTextField nachname;
  static JTextField email;
  static JFormattedTextField geburtstag;
  static JPasswordField passwort;
  
  
  void gui() {
  
    ListenerHome h = new ListenerHome();
    ListenerRegistrieren r = new ListenerRegistrieren();
  
      /**
       * Frames
       */
      // Frame Main
      frame = new JFrame("Main");
      frame.setSize(800, 600);
      frame.setLocation(600, 200);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
  
      /**
       * Panels
       */
      // Panel Main
      panel = new JPanel();
      panel.setSize(780, 475);
      panel.setLayout(null);
      frame.add(panel);
  
      /**
       * Labels
       */
      // Label Main
      label = new JLabel();
      label.setSize(200, 300);
      label.setLocation(230, 30);
      label.setVisible(true);
      label.setText("Guten Tag, was möchten Sie tun?");
      panel.add(label);
  
      // Label Username
      username_bezeichnung = new JLabel();
      username_bezeichnung.setBounds(65, 50, 120, 30);
      username_bezeichnung.setVisible(false);
      username_bezeichnung.setText("Username");
      panel.add(username_bezeichnung);
  
      // Label Vorname
      vorname_bezeichnung = new JLabel();
      vorname_bezeichnung.setBounds(65, 90, 120, 30);
      vorname_bezeichnung.setVisible(false);
      vorname_bezeichnung.setText("Vorname");
      panel.add(vorname_bezeichnung);
  
      // Label Nachname
      nachname_bezeichnung = new JLabel();
      nachname_bezeichnung.setBounds(65, 130, 120, 30);
      nachname_bezeichnung.setVisible(false);
      nachname_bezeichnung.setText("Nachname");
      panel.add(nachname_bezeichnung);
  
      // Label Geburtstag
      geburtstag_bezeichnung = new JLabel();
      geburtstag_bezeichnung.setBounds(390, 50, 120, 30);
      geburtstag_bezeichnung.setVisible(false);
      geburtstag_bezeichnung.setText("Geburtstag");
      panel.add(geburtstag_bezeichnung);
  
      // Label E-Mail
      email_bezeichnung = new JLabel();
      email_bezeichnung.setBounds(390, 90, 120, 30);
      email_bezeichnung.setVisible(false);
      email_bezeichnung.setText("E-Mail");
      panel.add(email_bezeichnung);
  
      // Label Passwort
      passwort_bezeichnung = new JLabel();
      passwort_bezeichnung.setBounds(390, 130, 120, 30);
      passwort_bezeichnung.setVisible(false);
      passwort_bezeichnung.setText("Passwort");
      panel.add(passwort_bezeichnung);
  
      /**
       * Buttons
       */
      // Button registrieren
      registrieren = new JButton("Registrieren");
      registrieren.setLocation(200, 320);
      registrieren.setSize(120, 50);
      registrieren.setVisible(true);
      registrieren.addActionListener(h);
      panel.add(registrieren);
  
      // Button login
      login = new JButton("Login");
      login.setLocation(350, 320);
      login.setSize(120, 50);
      login.setVisible(true);
      login.addActionListener(h);
      panel.add(login);
  
      // Button registrieren bestätigen
      registrierenBestätigen = new JButton("Registrieren");
      registrierenBestätigen.setLocation(390, 350);
      registrierenBestätigen.setSize(120, 50);
      registrierenBestätigen.setVisible(false);
      registrierenBestätigen.addActionListener(r);
      panel.add(registrierenBestätigen);
  
      /**
       * Textfields
       */
      // Textfield Username
      username = new JTextField("", 20);
      username.setBounds(150, 50, 120, 30);
      username.setVisible(false);
      panel.add(username);
  
      // Textfield Vorname
      vorname = new JTextField("", 20);
      vorname.setBounds(150, 90, 120, 30);
      vorname.setVisible(false);
      panel.add(vorname);
  
      // Textfield Nachname
      nachname = new JTextField("", 20);
      nachname.setBounds(150, 130, 120, 30);
      nachname.setVisible(false);
      panel.add(nachname);
  
      // Textfield Geburtstag
      geburtstag = new JFormattedTextField(new SimpleDateFormat("dd.MM.yyyy")); 
      geburtstag.setValue(new java.util.Date());
      geburtstag.setBounds(475, 90, 120, 30);
      geburtstag.setVisible(false);
      panel.add(geburtstag);
  
      // Textfield E-Mail
      email = new JTextField("", 25);
      email.setBounds(475, 50, 120, 30);
      email.setVisible(false);
      panel.add(email);
  
      // Passwortfield Passwort
      passwort = new JPasswordField("", 20);
      passwort.setBounds(475, 130, 120, 30);
      passwort.setVisible(false);
      panel.add(passwort);
  
  }
  }
  </code></pre>
  
  <p><strong>Class ListenerHome</strong></p>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  public class ListenerHome implements ActionListener {
  
  
  
  @Override
  public void actionPerformed(ActionEvent e) {
      if (e.getSource() == GUI.registrieren) {
          GUI.label.setVisible(false);
          GUI.username_bezeichnung.setVisible(true);
          GUI.vorname_bezeichnung.setVisible(true);
          GUI.nachname_bezeichnung.setVisible(true);
          GUI.geburtstag_bezeichnung.setVisible(true);
          GUI.email_bezeichnung.setVisible(true);
          GUI.passwort_bezeichnung.setVisible(true);
          GUI.registrieren.setVisible(false);
          GUI.login.setVisible(false);
          GUI.registrierenBestätigen.setVisible(true);
          GUI.username.setVisible(true);
          GUI.vorname.setVisible(true);
          GUI.nachname.setVisible(true);
          GUI.email.setVisible(true);
          GUI.geburtstag.setVisible(true);
          GUI.passwort.setVisible(true);
  
  
      }
  }
  }
  </code></pre>
  
  <p><strong>Class ListenerRegistrieren</strong></p>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.SQLException;
  
  public class ListenerRegistrieren implements ActionListener {
  
  
      public void actionPerformed(ActionEvent e) {        
          if(e.getSource() == GUI.registrierenBestätigen) {
                  addBenutzer();
          }
      }
  
  
  
  private static void addBenutzer() {
  
      try {
  
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection conn = DriverManager.getConnection("jdbc:odbc:MSAccess");
      PreparedStatement pstm;
      String sql = "Insert Into Benutzer ('Benutername', 'Vorname', 'Nachname', 'E-Mail') values ('?','?','?','?')";
      pstm = conn.prepareStatement(sql);
  
      // SQL Statements
      pstm.setString(1, GUI.username.getText());
      pstm.setString(2, GUI.vorname.getText());
      pstm.setString(3, GUI.nachname.getText());
      pstm.setString(4, GUI.email.getText());
      pstm.executeUpdate();
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  }
  </code></pre>
  
  <p><strong>Stack Trace</strong></p>
  
  <pre><code>java.lang.NullPointerException
  at sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter(Unknown Source)
  at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setChar(Unknown Source)
  at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setString(Unknown Source)
  at verwaltung.ListenerRegistrieren.addBenutzer(ListenerRegistrieren.java:37)
  at verwaltung.ListenerRegistrieren.actionPerformed(ListenerRegistrieren.java:20)
  at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
  at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
  at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
  at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
  at java.awt.Component.processMouseEvent(Unknown Source)
  at javax.swing.JComponent.processMouseEvent(Unknown Source)
  at java.awt.Component.processEvent(Unknown Source)
  at java.awt.Container.processEvent(Unknown Source)
  at java.awt.Component.dispatchEventImpl(Unknown Source)
  at java.awt.Container.dispatchEventImpl(Unknown Source)
  at java.awt.Component.dispatchEvent(Unknown Source)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
  at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
  at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
  at java.awt.Container.dispatchEventImpl(Unknown Source)
  at java.awt.Window.dispatchEventImpl(Unknown Source)
  at java.awt.Component.dispatchEvent(Unknown Source)
  at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
  at java.awt.EventQueue.access$200(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  at java.awt.EventQueue$4.run(Unknown Source)
  at java.awt.EventQueue$4.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  at java.awt.EventQueue.dispatchEvent(Unknown Source)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.run(Unknown Source)
  </code></pre>
  
  <p>I hope you can help me better now. Thanks for your help guys! </p>