0

I am having a problem getting the data retrieved from my "listallButton" to display properly into a JTable. The DB is sending the SELECT * FROM ATM information properly as a set of strings. I am not sure if it is being properly received and recorded as the JTables shows no data and is getting a nullpointerexception:

    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.net.Socket;
    import javax.swing.*;
    import javax.swing.border.Border;
    import javax.swing.table.*;
    import java.util.*;
    import javax.swing.table.AbstractTableModel;

    public class AtmView extends JApplet implements ActionListener{
        final static String banner = "WELCOME TO SHETH BANK!";
        JLabel bannerLabel;
        Border blackline;

        CardLayout myLayout;
        JPanel screensPanel; //main center panel

        JPanel loginPanel; //login panel
        JButton loginButton; //login button
        JTextField accountNumber; //login account number field
        JPasswordField password; //login password/PIN field
        String access_lvl; //login access level
        public String account;
        String pass;
        DataObject communicationObject;
        final static String LOGIN = "LOGIN";

        JPanel empPanel; //employee panel
        CardLayout empLayout; //employee center panel
        JButton createacctButton; //employee create account button
        JButton listallButton; //employee list all accounts button
        JPanel empcenterPanel;
        final static String EMP1 = "EMPLOYEE";
        String balance;
        String withdrawal_amount;
        String withdraw_amount;
        JLabel balanceDisplay;

  final static String LIST = "listallPanel";
  JPanel listallPanel;
  JTable table;
  String[] data;
  String[][] data2;
  String[] temp;
  String row;
  DefaultTableModel tbm; 
  JLabel listdisplay;
  String acclist;
  ArrayList<String> al;

  JButton empBackButton; //emp back
  JButton emplogoutButton; //emp logout
  JButton empwithdrawButton;

  JPanel custPanel; //customer panel
  final static String CUST = "CUSTOMER";

  JButton checkbalButton; //check balance
  JButton withdrawButton; //withdraw
  JButton depositButton; //deposit
  JButton transferButton; //transfer




  JLabel display; //server response display area


    @Override
  public void init(){

    getContentPane().setVisible(true);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().setBackground(Color.BLUE);
    //getContentPane().setBorder(blackline);
    bannerLabel = new JLabel(banner,JLabel.CENTER);
    bannerLabel.setVerticalTextPosition(JLabel.CENTER);
    bannerLabel.setHorizontalTextPosition(JLabel.CENTER);
    bannerLabel.setFont(new Font("Serif", Font.BOLD, 26));
    bannerLabel.setForeground(Color.yellow);
    blackline = BorderFactory.createLineBorder(Color.black);

    //bannerLabel.setBorder(blackline);
    add(bannerLabel, BorderLayout.NORTH);
    //bannerLabel.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Color.BLACK));

    myLayout = new CardLayout();
    screensPanel = new JPanel();
    screensPanel.setLayout(myLayout);
    add(screensPanel, BorderLayout.CENTER);

    //================ LOGIN VIEW ================================== 

    loginPanel = new JPanel(new GridLayout(3,1));
    loginPanel.setBackground(Color.BLUE);
    JLabel loginTitle = new JLabel("ENTER LOGIN INFO", JLabel.CENTER);
    //loginTitle.setVerticalAlignment(SwingConstants.TOP);
    loginTitle.setFont(new Font("Serif", Font.BOLD, 20));
    loginTitle.setForeground(Color.yellow);
    loginPanel.add(loginTitle);

    JPanel accountInfo = new JPanel(new GridLayout(2,1));
    accountInfo.setBackground(Color.blue);
    JPanel accNum = new JPanel();
    accNum.setBackground(Color.BLUE);
    JLabel accLabel = new JLabel("Account Number: ", JLabel.CENTER);
    accLabel.setFont(new Font("Serif", Font.BOLD, 14));
    accLabel.setForeground(Color.yellow);
    accountNumber = new JTextField(4);
    accountNumber.setHorizontalAlignment(JTextField.CENTER);
    accNum.add(accLabel);
    accLabel.setLabelFor(accountNumber);
    accNum.add(accountNumber); 
    accountInfo.add(accNum);
    JPanel pw = new JPanel();
    pw.setBackground(Color.BLUE);
    JLabel pwLabel = new JLabel("Password/PIN: ", JLabel.CENTER);
    pwLabel.setFont(new Font("Serif", Font.BOLD, 14));
    pwLabel.setForeground(Color.yellow);
    password = new JPasswordField(4);
    password.setHorizontalAlignment(JTextField.CENTER);
    pw.add(pwLabel);
    pwLabel.setLabelFor(password);
    pw.add(password);
    accountInfo.add(pw);
    loginPanel.add(accountInfo);

    JPanel logBut = new JPanel();
    loginButton = new JButton("Login");
    loginButton.addActionListener(this);
    logBut.setBackground(Color.blue);
    logBut.add(loginButton);

    loginPanel.add(logBut);

    screensPanel.add(loginPanel, "LOGIN");

    //================ EMPLOYEE VIEW ==================================

    empPanel = new JPanel(new BorderLayout());
    empPanel.setBackground(Color.BLUE);
    JLabel empLabel = new JLabel("Employee View",JLabel.CENTER);
    empLabel.setVerticalTextPosition(JLabel.CENTER);
    empLabel.setHorizontalTextPosition(JLabel.CENTER);
    empLabel.setFont(new Font("Serif", Font.BOLD, 20));
    empLabel.setForeground(Color.yellow);
    empPanel.add(empLabel, BorderLayout.NORTH);

    empLayout = new CardLayout();
    empcenterPanel = new JPanel();
    empcenterPanel.setBackground(Color.blue);
    empcenterPanel.setLayout(empLayout);
    empPanel.add(empcenterPanel, BorderLayout.CENTER);

    JPanel empbuttonPanel = new JPanel(new GridLayout(3,2));
    empbuttonPanel.setBackground(Color.blue);
    checkbalButton = new JButton("Check Balance"); 
    checkbalButton.addActionListener(this);
    empbuttonPanel.add(checkbalButton);
    withdrawButton = new JButton("Withdraw"); 
    withdrawButton.addActionListener(this);
    empbuttonPanel.add(withdrawButton);
    depositButton = new JButton("Deposit"); 
    depositButton.addActionListener(this);
    empbuttonPanel.add(depositButton);
    transferButton = new JButton("Transfer");
    transferButton.addActionListener(this);
    empbuttonPanel.add(transferButton);
    createacctButton = new JButton("Create account");
    createacctButton.addActionListener(this);
    empbuttonPanel.add(createacctButton);
    listallButton = new JButton("List all accounts");
    listallButton.addActionListener(this);
    empbuttonPanel.add(listallButton);
    empcenterPanel.add(empbuttonPanel, "EmpButtonPanel");


    createPanel = new JPanel(new GridLayout(6,1));
    createPanel.setBackground(Color.blue);
    JLabel createTitle = new JLabel("Enter new account info: ",JLabel.CENTER);
    createTitle.setVerticalTextPosition(JLabel.CENTER);
    createTitle.setHorizontalTextPosition(JLabel.CENTER);
    createTitle.setFont(new Font("Serif", Font.BOLD, 18));
    createTitle.setForeground(Color.yellow);
    createPanel.add(createTitle);

    JPanel cloginPanel = new JPanel(new FlowLayout());
    cloginPanel.setBackground(Color.blue);
    JLabel cloginLabel = new JLabel("Account number: ",JLabel.CENTER);
    cloginLabel.setVerticalTextPosition(JLabel.CENTER);
    cloginLabel.setHorizontalTextPosition(JLabel.CENTER);
    cloginLabel.setFont(new Font("Serif", Font.BOLD, 14));
    cloginLabel.setForeground(Color.yellow);
    cloginPanel.add(cloginLabel);
    createloginField = new JTextField(4);
    createloginField.setHorizontalAlignment(JTextField.CENTER);
    cloginLabel.setLabelFor(createloginField);
    cloginPanel.add(createloginField);
    createPanel.add(cloginPanel);
    JPanel cpinPanel = new JPanel(new FlowLayout());
    cpinPanel.setBackground(Color.blue);
    JLabel cpinLabel = new JLabel("PIN: ",JLabel.CENTER);
    cpinLabel.setVerticalTextPosition(JLabel.CENTER);
    cpinLabel.setHorizontalTextPosition(JLabel.CENTER);
    cpinLabel.setFont(new Font("Serif", Font.BOLD, 14));
    cpinLabel.setForeground(Color.yellow);
    cpinPanel.add(cpinLabel);
    createpinField = new JTextField(4);
    createpinField.setHorizontalAlignment(JTextField.CENTER);
    cloginLabel.setLabelFor(createpinField);
    cpinPanel.add(createpinField);
    createPanel.add(cpinPanel);
    JPanel cbalPanel = new JPanel(new FlowLayout());
    cbalPanel.setBackground(Color.blue);
    JLabel cbalLabel = new JLabel("Starting balance: ",JLabel.CENTER);
    cbalLabel.setVerticalTextPosition(JLabel.CENTER);
    cbalLabel.setHorizontalTextPosition(JLabel.CENTER);
    cbalLabel.setFont(new Font("Serif", Font.BOLD, 14));
    cbalLabel.setForeground(Color.yellow);
    cbalPanel.add(cbalLabel);
    createbalanceField = new JTextField(10);
    createbalanceField.setHorizontalAlignment(JTextField.CENTER);
    cbalLabel.setLabelFor(createbalanceField);
    cbalPanel.add(createbalanceField);
    createPanel.add(cbalPanel);
    JPanel clvlPanel = new JPanel(new FlowLayout());
    clvlPanel.setBackground(Color.blue);
    JLabel clvlLabel = new JLabel("Access level (1 for Employee, 2 for Customer): ",JLabel.CENTER);
    clvlLabel.setVerticalTextPosition(JLabel.CENTER);
    clvlLabel.setHorizontalTextPosition(JLabel.CENTER);
    clvlLabel.setFont(new Font("Serif", Font.BOLD, 14));
    clvlLabel.setForeground(Color.yellow);
    clvlPanel.add(clvlLabel);
    createlvlField = new JTextField(1);
    createlvlField.setHorizontalAlignment(JTextField.CENTER);
    cbalLabel.setLabelFor(createlvlField);
    clvlPanel.add(createlvlField);
    createPanel.add(clvlPanel);
    JPanel createbutPanel = new JPanel();
    createbutPanel.setBackground(Color.blue);
    createButton = new JButton("Create");
    createButton.addActionListener(this);
    createbutPanel.add(createButton);
    createPanel.add(createbutPanel);
    empcenterPanel.add(createPanel, "createPanel");

    listallPanel = new JPanel(new BorderLayout());
    listallPanel.setBackground(Color.blue);
    JLabel listTitle = new JLabel("All accounts in system: ",JLabel.CENTER);
    listTitle.setVerticalTextPosition(JLabel.CENTER);
    listTitle.setHorizontalTextPosition(JLabel.CENTER);
    listTitle.setFont(new Font("Serif", Font.BOLD, 16));
    listTitle.setForeground(Color.yellow);
    listallPanel.add(listTitle,BorderLayout.NORTH);

    String[] columnNames = {"Account Number","PIN","Access Level","Balance",};
    String [][] rowTest = {{"1111","1111","1","1000",},{"1111","1111","1","1000",}};
    String delimiter = ",";

    tbm = new DefaultTableModel();  
    tbm.addColumn("Account Number"); 
    tbm.addColumn("PIN"); 
    tbm.addColumn("Access Level"); 
    tbm.addColumn("Balance");

    table = new JTable(tbm);
    JScrollPane scrollPane = new JScrollPane(table);
    listallPanel.add(scrollPane,BorderLayout.CENTER);        

    empcenterPanel.add(listallPanel, "listallPanel");


    JPanel logoutPanel = new JPanel(new FlowLayout());
    emplogoutButton = new JButton("Logout");
    emplogoutButton.addActionListener(this);
    empBackButton = new JButton("Back");
    empBackButton.addActionListener(this);
    logoutPanel.setBackground(Color.blue);
    logoutPanel.add(emplogoutButton);
    logoutPanel.add(empBackButton);
    empPanel.add(logoutPanel, BorderLayout.SOUTH);

    screensPanel.add(empPanel, "EMPLOYEE");

    //================ CUSTOMER VIEW ==================================


    }



  public void actionPerformed(ActionEvent event) {
      if (event.getSource() == loginButton) {
          account = accountNumber.getText();
          pass = password.getText();
          String query = "SELECT access_level FROM ATM a WHERE a.account_number='"+account+"' AND a.pin='"+pass+"'";
          try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              access_lvl = communicationObject.getMessage();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e);}
          if ((access_lvl.charAt(0)) == '1') {
              myLayout.show(screensPanel, EMP1);
              empLayout.first(empcenterPanel);}
          else {myLayout.show(screensPanel, CUST); } }

      else if(event.getSource() == emplogoutButton) {
          accountNumber.setText("");
          password.setText("");
          account = "";
          pass = "";
          empLayout.first(empcenterPanel);
          myLayout.show(screensPanel, LOGIN);
          doLayout();}

      else if(event.getSource() == checkbalButton) {

      String query = "SELECT balance FROM ATM a WHERE a.account_number='"+account+"' AND a.pin='"+pass+"'";
          try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              balance = communicationObject.getMessage();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e);}
          balanceDisplay.setText(balance);
          //balanceDisplayPanel.add(balanceDisplay);
          //checkBalancePanel.add(balanceDisplayPanel);
          empLayout.show(empcenterPanel, EMPBAL); }

      else if(event.getSource() == empBackButton) {
          empLayout.first(empcenterPanel); }

      else if(event.getSource() == withdrawButton) {
          empLayout.show(empcenterPanel, EMPWITH); }  

      else if(event.getSource() == empwithdrawButton) {
      withdraw_amount = withdrawField.getText();
      Integer w_amt = Integer.valueOf(withdraw_amount);
      String query = "SELECT balance FROM ATM a WHERE a.account_number='"+account+"' AND a.pin='"+pass+"'";
          try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              balance = communicationObject.getMessage();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e);}
          Integer oldbalance = Integer.valueOf(balance);
          Integer newbalanceamount = oldbalance - w_amt;
          balance2 = "" + newbalanceamount;
          String query2 = "UPDATE ATM SET balance='"+balance2+"' WHERE account_number='"+account+"' AND pin='"+pass+"'";
          try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query2);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              //balance = communicationObject.getMessage();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e); }
      withdrawField.setText("");
      empLayout.first(empcenterPanel); }

      else if(event.getSource() == depositButton) {
         empLayout.show(empcenterPanel, EMPDEP); }

      else if(event.getSource() == empdepositButton) {
      deposit_amount = depositField.getText();
      Integer d_amt = Integer.valueOf(deposit_amount);
      String query = "SELECT balance FROM ATM a WHERE a.account_number='"+account+"' AND a.pin='"+pass+"'";
          try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              balance = communicationObject.getMessage();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e);}
          Integer oldbalance2 = Integer.valueOf(balance);
          Integer newbalanceamount2 = oldbalance2 + d_amt;
          balance3 = "" + newbalanceamount2;
          String query2 = "UPDATE ATM SET balance='"+balance3+"' WHERE account_number='"+account+"' AND pin='"+pass+"'";
          try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query2);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              //balance = communicationObject.getMessage();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e);}
          depositField.setText("");
          empLayout.first(empcenterPanel); }

      else if(event.getSource() == transferButton) {
         empLayout.show(empcenterPanel, EMPTNS); }

      else if(event.getSource() == transferamountButton) {
      fromAccount = fromField.getText();
      toAccount = toField.getText();
      transAmount = transferAmount.getText();
      Integer t_amt = Integer.valueOf(transAmount);
      String query = "SELECT balance FROM ATM a WHERE a.account_number='"+fromAccount+"'";
          try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              balance = communicationObject.getMessage();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e);}
      Integer fromBalance = Integer.valueOf(balance);
      String query2 = "SELECT balance FROM ATM a WHERE a.account_number='"+toAccount+"'";
          try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query2);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              balance = communicationObject.getMessage();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e);}
      Integer toBalance = Integer.valueOf(balance);
      Integer newFromBalance = fromBalance - t_amt;
      Integer newToBalance = toBalance + t_amt;
      String newFBalance = "" + newFromBalance;
      String newTBalance = "" + newToBalance;
      String query3 = "UPDATE ATM SET balance='"+newFBalance+"' WHERE account_number='"+fromAccount+"'";
      try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query3);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              //balance = communicationObject.getMessage();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e);}
      String query4 = "UPDATE ATM SET balance='"+newTBalance+"' WHERE account_number='"+toAccount+"'";    
      try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query4);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              //balance = communicationObject.getMessage();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e);}      
      toField.setText("");
      fromField.setText("");
      transferAmount.setText("");
      empLayout.first(empcenterPanel); }     

      else if(event.getSource() == createacctButton) {
         empLayout.show(empcenterPanel, CREATE); }

      else if(event.getSource() == createButton) {
          createLogin = createloginField.getText();
          createPin = createpinField.getText();
          createLvl = createlvlField.getText();
          createBalance = createbalanceField.getText();
          String query = "INSERT INTO ATM VALUES ("+createLogin+","+createPin+","+createLvl+","+createBalance+")";
          try {
              communicationObject = new DataObject();
              communicationObject.setMessage(query);
              Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
              ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
              ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
              myOutputStream.writeObject(communicationObject);
              communicationObject = (DataObject)myInputStream.readObject();
              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }   
          catch(Exception e){System.out.println(e);}
          createloginField.setText("");
          createpinField.setText("");
          createlvlField.setText("");
          createbalanceField.setText("");
          empLayout.first(empcenterPanel); }

        else if(event.getSource() == listallButton) {
          String query = "SELECT * FROM ATM";
          String delimiter = ",";
          String input = "go";
          int count=0;
          al = new ArrayList<String>();

              try {
                  communicationObject = new DataObject();
                  communicationObject.setMessage(query);
                  Socket socketToServer = new Socket("sunlab32.njit.edu",31414);
                  ObjectOutputStream myOutputStream = new ObjectOutputStream(socketToServer.getOutputStream());
                  ObjectInputStream myInputStream = new ObjectInputStream(socketToServer.getInputStream());
                  myOutputStream.writeObject(communicationObject);
                  communicationObject = (DataObject)myInputStream.readObject();
                  input = communicationObject.getMessage();
                  if (input != "stop") {
                      al.add(input);
                      data[count] = input;
                      count++; }

                  for (int i=0;i<data.length;i++) {
                      row = data[i];
                      temp = row.split(delimiter);
                      tbm.addRow(new String[] {temp[0],temp[1],temp[2],temp[3]}); } 

                  table.setModel(tbm);
                  table.repaint();




              //Object Object_Array[]=al.toArray();
              //data=new String[Object_Array.length];
              //for (int i=0;i<data.length;i++) {data[i]=Object_Array[i].toString();}


              myOutputStream.close();
              myInputStream.close();
              socketToServer.close(); }
              catch(Exception e){System.out.println(e);}   

          empLayout.show(empcenterPanel, LIST);  }



        }   }  

Stacktrace:

java.lang.NullPointerException at AtmView.actionPerformed(AtmView.java:757) 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.EventQueue.dispatchEventImpl(Unknown Source) at 
java.awt.EventQueue.access$000(Unknown Source) at 
java.awt.EventQueue$3.run(Unknown Source) at 
java.awt.EventQueue$3.run(Unknown Source) at 
Bart
  • 19,692
  • 7
  • 68
  • 77
paul62285
  • 21
  • 5
  • StacKTrace? where is the null pointer exception occurring? – ChadNC May 01 '12 at 14:06
  • im not sure how to StackTrace...all i see in the console is java.lang.NullPointerException...the error occurs when i load the panel with the JTable – paul62285 May 01 '12 at 14:40
  • @ChadNC java.lang.NullPointerException at AtmView.actionPerformed(AtmView.java:757) 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) – paul62285 May 01 '12 at 14:55
  • 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) – paul62285 May 01 '12 at 14:55
  • at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(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) – paul62285 May 01 '12 at 14:56
  • 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) – paul62285 May 01 '12 at 14:56
  • 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) – paul62285 May 01 '12 at 14:56
  • I have added the stacktrace to the question. Please do this yourself next time. I only added a part as the number of characters in a question is limited – Robin May 01 '12 at 16:09

2 Answers2

1

The null point exception is probably caused by some empty column in DB. Your practice is not good, if there are a huge number of records in DB it will crash your program, a better way is to use paging to avoid loading a large number of records.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user1335794
  • 1,082
  • 6
  • 12
0

Your issue is that you have not initialized your data which is String array.

First access to this instance variable is being done here after the query has been executed

if (input != "stop") {
    al.add(input);
    data[count] = input;
    count++;
}

At this point data is null and you are trying to access its 0th element hence NPE.

On a side note:

Don't do such extensive work on the EventModelThread, use SwingWorker to perform your data load operation and then push the changes on the UI. Swing is single threaded, you block the UI when you are performing data load.

Though in your current scenario it won't have much impact considering you just have 5 rows but in case your rows are like say 1000 or so your UI will be come unresponsive. Also, dont expect people to see all 1000s of rows in one page, have pagination.

Pagination Sample Code

Swing Worker Tutorial

Community
  • 1
  • 1
mprabhat
  • 20,107
  • 7
  • 46
  • 63