title: nullpointerexception while calling a constructor
body: <p>thanks for having time reading this. my problem here is that when i call the other class it gives me so many error and i dont know how to fix it. im hope you can :) ty and have a good day :)</p>
  
  <p>here is my code </p>
  
  <pre><code>public class Xavier1 extends JFrame implements ActionListener,Runnable
  {
  JButton a[] = new JButton [10];
  JLabel pin,acc;
  JTextField acc1;
  JButton del,ok,crt;
  int c=0,d=0,e=0;
  JPasswordField pin1;
  JFrame x;
  String us,pw;
  JButton res,back,next;
  JLabel n,accn,bal,age,sex,dep,pins;
  JFrame X,r;
  JTextField n1,accn1,bal1,sex1,age1,dep1;
  JPasswordField pins1;
  JLabel Xn,Xacc,Xbal,Xage,Xsex;
  String xn,xacc,xbal,xage,xsex;
  
  
  
  public void run()
  {
  
  }
  
  public Xavier1()
  {
      x = new JFrame("ATM");
      x.setLayout(null);
      x.setBounds(400,100,550,500);
      x.setVisible(true);
  
      JPanel x3 = new JPanel();
      x.add(x3);
      x3.setVisible(true);
      x3.setBounds(150,420,250,100);
      crt = new JButton("Create Account");
      crt.addActionListener(this);
      x3.add(crt);
  
      JPanel x2 = new JPanel();
      x.add(x2);
      x2.setBounds(150,10,250,100);
      x2.setVisible(true);
      x2.setLayout(new GridLayout(4,2));
      pin = new JLabel("PIN");
      acc = new JLabel("ACCOUNT NUMBER");
      pin1 = new JPasswordField(20);
      acc1 = new JTextField(20);
  
      x2.add(acc);
      x2.add(acc1);
      x2.add(pin);
      x2.add(pin1);
  
  
      JPanel x1 = new JPanel();
      x.add(x1);
      x1.setBounds(150,200,250,200);
      x1.setVisible(true);
      x1.setLayout(new GridLayout(4,3));
  
      for(int b=0;b&lt;10;b++)
      {
          a[b] = new JButton();
          a[b].setText(Integer.toString(b));
          x1.add(a[b]);
          a[b].addActionListener(this);
      }
      ok = new JButton("OK");
      ok.addActionListener(this);
      del = new JButton("DEL");
      del.addActionListener(this);
      x1.add(ok);
      x1.add(del);
  
  
  
  
  }
  public static void main (String args[])
  {
      Xavier1 xs = new Xavier1();
      Thread xd = new Thread(xs);
      xd.setDaemon(true);
  
  
  
  }
  public void actionPerformed(ActionEvent z)
  {
      Object zz = z.getSource();
  
      if(e == 0)
      {
          for(int c=0;c&lt;a.length;c++)
          {
              if(zz == a[c])
              {
              acc1.setText(acc1.getText()+a[c].getText());
              }
  
          }
      }
      if(zz == ok)
      {
          e++;
      }
      if(e==2)
      {
          GateKeeper();
  
  
      }
      if(e == 1)
      {
          for(int d=0;d&lt;a.length;d++)
          {
              if(zz == a[d])
              {
              pin1.setText(pin1.getText()+a[d].getText());
              }
  
          }
  
      }
      if(zz == crt)
      {
          Reg rs = new Reg();
          Thread sr = new Thread(rs);
          sr.start();
          x.setVisible(false);
      }
      if(zz == del)
      {
          if(e == 0)
          {
              acc1.setText(null);
          }
          if(e == 1)
          {
              pin1.setText(null);
          }
      }
  
  }
  public void GateKeeper()
  {
      try
      {
          Scanner sc = new Scanner(new File("DATABASE.txt"));
          int loop = sc.nextInt();
          sc.nextLine();
          for(int gk=0;gk&lt;loop;gk++)
          {
              String ps[] = sc.nextLine().split(" ");
              us = ps[0];
              pw = ps[1];
              if(acc1.getText().equals(us));
              {
                  if(pin1.getText().equals(pw))
                  {
                      xn = ps[2];
                      xage = ps[3];
                      xsex = ps[4];
                      xbal = ps[5];
                      xacc = ps[0];
  
  
  
                              Xn = new JLabel("NAME: "+xn);
                              Xacc = new JLabel("ACCOUNT NUMBER: "+xacc);
                              Xage = new JLabel("AGE: "+xage);
                              Xsex = new JLabel("SEX: "+xsex);
                              Xbal = new JLabel("BALANCE: "+xbal);
  
                          Bank b = new Bank();
                          Thread xb = new Thread(b);
                          xb.start();
                          x.setVisible(false);
  
                          break;
  
                  }
              }
  
          }
      }
      catch(FileNotFoundException s)
      {
  
      }
  }
  }
  </code></pre>
  
  <p>and this is the code that im have a problem.</p>
  
  <pre><code>public void GateKeeper()
  {
      try
      {
          Scanner sc = new Scanner(new File("DATABASE.txt"));
          int loop = sc.nextInt();
          sc.nextLine();
          for(int gk=0;gk&lt;loop;gk++)
          {
              String ps[] = sc.nextLine().split(" ");
              us = ps[0];
              pw = ps[1];
              if(acc1.getText().equals(us));
              {
                  if(pin1.getText().equals(pw))
                  {
                      xn = ps[2];
                      xage = ps[3];
                      xsex = ps[4];
                      xbal = ps[5];
                      xacc = ps[0];
  
  
  
                              Xn = new JLabel("NAME: "+xn);
                              Xacc = new JLabel("ACCOUNT NUMBER: "+xacc);
                              Xage = new JLabel("AGE: "+xage);
                              Xsex = new JLabel("SEX: "+xsex);
                              Xbal = new JLabel("BALANCE: "+xbal);
  
                          Bank b = new Bank();
                          Thread xb = new Thread(b);
                          xb.start();
                          x.setVisible(false);
  
                          break;
  
                  }
              }
  
          }
      }
      catch(FileNotFoundException s)
      {
  
      }
  }
  </code></pre>
  
  <p>and this is the class that the GateKeeper is calling .</p>
  
  <pre><code>public class Bank extends Xavier1
  {
  
  
  
  public void reader()
  {
      try
      {
      FileReader fr = new FileReader("DATABASE.TXT");
      BufferedReader br = new BufferedReader(fr);
      }
      catch(FileNotFoundException s)
      {
  
      }
  }
  
  
  public Bank()
  {
      X = new JFrame("BANK");
      X.setVisible(true);
      X.setBounds(400,100,550,500);
      X.setLayout(null);
      x.setVisible(false);
  
  
      JPanel info = new JPanel();
      X.add(info);
      info.setVisible(true);
      info.setBounds(50,10,400,400);
      info.setLayout(new GridLayout(7,2));
  
  
  
      info.add(Xn);
      info.add(Xacc);
      info.add(Xage);
      info.add(Xsex);
      info.add(Xbal);
  
  
  
  
  
  
  }
  public static void main(String args[])
  {
  
  
  }
  public void actionPerformed(ActionEvent z1)
  {
      Object z2 = z1.getSource();
  }
  
  }
  </code></pre>
  
  <p>and this is the errors i get :(</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  at java.awt.Container.addImpl(Container.java:1086)
  at java.awt.Container.add(Container.java:410)
  at Bank.&lt;init&gt;(Bank.java:43)
  at Xavier1.GateKeeper(Xavier1.java:183)
  at Xavier1.actionPerformed(Xavier1.java:117)
  at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
  at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
  at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
  at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
  at java.awt.Component.processMouseEvent(Component.java:6505)
  at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
  at java.awt.Component.processEvent(Component.java:6270)
  at java.awt.Container.processEvent(Container.java:2229)
  at java.awt.Component.dispatchEventImpl(Component.java:4861)
  at java.awt.Container.dispatchEventImpl(Container.java:2287)
  at java.awt.Component.dispatchEvent(Component.java:4687)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
  at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
  at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
  at java.awt.Container.dispatchEventImpl(Container.java:2273)
  at java.awt.Window.dispatchEventImpl(Window.java:2719)
  at java.awt.Component.dispatchEvent(Component.java:4687)
  at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
  at java.awt.EventQueue.access$200(EventQueue.java:103)
  at java.awt.EventQueue$3.run(EventQueue.java:694)
  at java.awt.EventQueue$3.run(EventQueue.java:692)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
  at java.awt.EventQueue$4.run(EventQueue.java:708)
  at java.awt.EventQueue$4.run(EventQueue.java:706)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
  </code></pre>