title: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException in JAVA
body: <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  package Employees;
  
  import java.sql.*;
  import javax.swing.*;
  
  public class Workers extends javax.swing.JFrame {
  
      Connection con;
      Statement stmt;
      ResultSet rs;
      public Workers() {
          initComponents();
          DBConnect();
      }
  
      public void DBConnect(){
          try{
          String host = "jdbc:derby://localhost:1527/Emplyee";
          String db_uname = "ikot";
          String db_pass = "5556sick6";
          con = DriverManager.getConnection(host, db_uname, db_pass);
          stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
          String sql = "SELECT * FROM Workers";
          ResultSet rs = stmt.executeQuery(sql);
          rs.next();
          int id_col = rs.getInt("ID");
          String id = Integer.toString(id_col);
          String fname = rs.getString("First_name");
          String lname = rs.getString("Last_name");
          String job = rs.getString("Job_title");
          textID.setText(id);
          textFirstName.setText(fname);
          textLastName.setText(lname);
          textJobTitle.setText(job);
          }
          catch(SQLException err){
              JOptionPane.showMessageDialog(Workers.this, err.getMessage());
          }
      }
  
      /**
       * This method is called from within the constructor to initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is always
       * regenerated by the Form Editor.
       */
      @SuppressWarnings("unchecked")
      // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
      private void initComponents() {
  
          jPanel1 = new javax.swing.JPanel();
          textID = new javax.swing.JTextField();
          textFirstName = new javax.swing.JTextField();
          textLastName = new javax.swing.JTextField();
          textJobTitle = new javax.swing.JTextField();
          jLabel1 = new javax.swing.JLabel();
          jPanel2 = new javax.swing.JPanel();
          btnFirst = new javax.swing.JButton();
          btnPrevious = new javax.swing.JButton();
          btnNext = new javax.swing.JButton();
          btnLast = new javax.swing.JButton();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
          jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
          jLabel1.setText("Job Title");
  
          javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
          jPanel1.setLayout(jPanel1Layout);
          jPanel1Layout.setHorizontalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addContainerGap()
                          .addComponent(textID, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                          .addComponent(textFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                          .addComponent(textLastName))
                      .addGroup(jPanel1Layout.createSequentialGroup()
                          .addGap(31, 31, 31)
                          .addComponent(jLabel1)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                          .addComponent(textJobTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)))
                  .addContainerGap())
          );
          jPanel1Layout.setVerticalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel1Layout.createSequentialGroup()
                  .addGap(31, 31, 31)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(textID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(textFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(textLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGap(32, 32, 32)
                  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(textJobTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(jLabel1))
                  .addContainerGap(42, Short.MAX_VALUE))
          );
  
          textID.getAccessibleContext().setAccessibleName("");
  
          btnFirst.setText("First");
  
          btnPrevious.setText("Previous");
          btnPrevious.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  btnPreviousActionPerformed(evt);
              }
          });
  
          btnNext.setText("Next");
          btnNext.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  btnNextActionPerformed(evt);
              }
          });
  
          btnLast.setText("Last");
  
          javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
          jPanel2.setLayout(jPanel2Layout);
          jPanel2Layout.setHorizontalGroup(
              jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel2Layout.createSequentialGroup()
                  .addGap(20, 20, 20)
                  .addComponent(btnFirst)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(btnPrevious)
                  .addGap(36, 36, 36)
                  .addComponent(btnNext)
                  .addGap(36, 36, 36)
                  .addComponent(btnLast)
                  .addGap(22, 22, 22))
          );
          jPanel2Layout.setVerticalGroup(
              jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel2Layout.createSequentialGroup()
                  .addGap(39, 39, 39)
                  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(btnFirst)
                      .addComponent(btnPrevious)
                      .addComponent(btnNext)
                      .addComponent(btnLast))
                  .addContainerGap(38, Short.MAX_VALUE))
          );
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                      .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                  .addContainerGap())
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(18, 18, 18)
                  .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addContainerGap(26, Short.MAX_VALUE))
          );
  
          pack();
      }// &lt;/editor-fold&gt;                        
  
      private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {                                        
          try{
              if(rs.next()){
                  int col = rs.getInt("ID");
                  String id_no = Integer.toString(col);
                  String f_name = rs.getString("First_name");
                  String l_name = rs.getString("Last_name");
                  String job_title = rs.getString("Job_title");
  
                  textID.setText(id_no);
                  textFirstName.setText(f_name);
                  textLastName.setText(l_name);
                  textJobTitle.setText(job_title);
              }
              else{
                  rs.previous();
                  JOptionPane.showMessageDialog(Workers.this, "End of file");
              }
          }
          catch(SQLException err){
              JOptionPane.showMessageDialog(Workers.this, err.getMessage());
          }
      }                                       
  
      private void btnPreviousActionPerformed(java.awt.event.ActionEvent evt) {                                            
          // TODO add your handling code here:
      }                                           
  
  
      public static void main(String args[]) {
          /* Set the Nimbus look and feel */
          //&lt;editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "&gt;
          /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
           * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
           */
          try {
              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                  if ("Nimbus".equals(info.getName())) {
                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
                      break;
                  }
              }
          } catch (ClassNotFoundException ex) {
              java.util.logging.Logger.getLogger(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (InstantiationException ex) {
              java.util.logging.Logger.getLogger(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex) {
              java.util.logging.Logger.getLogger(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
              java.util.logging.Logger.getLogger(Workers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          }
          //&lt;/editor-fold&gt;
  
          /* Create and display the form */
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  new Workers().setVisible(true);
              }
          });
      }
  
      // Variables declaration - do not modify                     
      private javax.swing.JButton btnFirst;
      private javax.swing.JButton btnLast;
      private javax.swing.JButton btnNext;
      private javax.swing.JButton btnPrevious;
      private javax.swing.JLabel jLabel1;
      private javax.swing.JPanel jPanel1;
      private javax.swing.JPanel jPanel2;
      private javax.swing.JTextField textFirstName;
      private javax.swing.JTextField textID;
      private javax.swing.JTextField textJobTitle;
      private javax.swing.JTextField textLastName;
      // End of variables declaration                   
  }
  </code></pre>
  
  <pre>
  Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at Employees.Workers.btnNextActionPerformed(Workers.java:185)
      at Employees.Workers.access$100(Workers.java:16)
      at Employees.Workers$2.actionPerformed(Workers.java:126)
      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:6516)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
      at java.awt.Component.processEvent(Component.java:6281)
      at java.awt.Container.processEvent(Container.java:2229)
      at java.awt.Component.dispatchEventImpl(Component.java:4872)
      at java.awt.Container.dispatchEventImpl(Container.java:2287)
      at java.awt.Component.dispatchEvent(Component.java:4698)
      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:4698)
      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)
  </pre>   
  
  <p>Every time I am running that code it is showing those errors if I press the next button.
  I am running this code on NetBeans 8.0.2 in Windows7 32bit machine.
  That would be so much helpful if somebody can help me getting through this problem.</p>