Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Run Time Error!!!

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Run Time Error!!!

    package Employee;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import javax.swing.JOptionPane;

    public class newemp extends javax.swing.JFrame {

    Connection con;
    Statement stmt;
    ResultSet rs;


    public newemp() {
    initComponents();
    DoConnect();
    }

    public void DoConnect()
    {
    try
    {
    String host = "jdbc:derby://localhost:1527/employe";
    String uName = "selvan";
    String uPass = "selvan";
    Connection con = DriverManager.getConnection( host, uName, uPass );

    }
    catch ( SQLException err )
    {
    JOptionPane.showMessageDialog(null, err.getMessage());
    }

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    empname = new javax.swing.JTextField();
    empid = new javax.swing.JTextField();
    salary = new javax.swing.JTextField();
    occupation = new javax.swing.JTextField();
    add = new javax.swing.JButton();
    jButton1 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

    jLabel1.setText("Employee Name");

    jLabel2.setText("Employee ID");

    jLabel3.setText("Salary");

    jLabel4.setText("Occupation");

    salary.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    salaryActionPerformed(evt);
    }
    });

    add.setText("ADD");
    add.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    addActionPerformed(evt);
    }
    });

    jButton1.setText("<< Back");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(50, 50, 50)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addComponent(jLabel1)
    .addComponent(jLabel2)
    .addComponent(jLabel3)
    .addComponent(jLabel4))
    .addGap(100, 100, 100)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
    .addComponent(empname)
    .addComponent(empid)
    .addComponent(salary)
    .addComponent(occupation, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
    .addGap(136, 136, 136)
    .addComponent(add)
    .addContainerGap(208, Short.MAX_VALUE))
    .addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
    .addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE)
    .addComponent(jButton1)
    .addGap(24, 24, 24))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(56, 56, 56)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jLabel1)
    .addComponent(empname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(28, 28, 28)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jLabel2)
    .addComponent(empid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
    .addGroup(layout.createSequentialGroup()
    .addGap(43, 43, 43)
    .addComponent(add)))
    .addGap(13, 13, 13)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jLabel3)
    .addComponent(salary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(45, 45, 45)
    .addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
    .addComponent(jLabel4)
    .addComponent(occupation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 100, Short.MAX_VALUE)
    .addComponent(jButton1)
    .addGap(40, 40, 40))
    );

    pack();
    }// </editor-fold>

    private void salaryActionPerformed(java.awt.event.ActionEvent evt) {

    }


    private void addActionPerformed(java.awt.event.ActionEvent evt) {

    try
    {
    stmt = con.createStatement();
    String sql = "INSERT INTO SELVAN.WORKERS VALUES ('" +empid.getText()+ "' and '" + empname.getText()+ "' and '" + salary.getText() + "')";
    rs = stmt.executeQuery(sql);
    String msg;
    msg = " "+ empname.getText() + " are added to our company.The emp ID is" + empid.getText();
    empid.setText("");
    empname.setText("");
    salary.setText("");
    JOptionPane.showMessageDialog(null,msg);

    }

    catch (SQLException err)
    {
    JOptionPane.showMessageDialog(null, err.getMessage());
    }

    }


    public static void main(String args[]) {

    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
    * For details see How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)
    */
    try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
    javax.swing.UIManager.setLookAndFeel(info.getClass Name());
    break;
    }
    }
    } catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(newemp.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(newemp.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(newemp.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(newemp.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>


    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new newemp().setVisible(true);
    }
    });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton add;
    private javax.swing.JTextField empid;
    private javax.swing.JTextField empname;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField occupation;
    private javax.swing.JTextField salary;
    // End of variables declaration
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Run Time Error!!!

    Please copy the full text of the error message and paste it here.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Run Time Error!!!

    K
    Quote Originally Posted by Norm View Post
    Please copy the full text of the error message and paste it here.

    Please edit your post and wrap your code with
    [code=java]
    run:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Employee.newemp.addActionPerformed(newemp.java:144 )
    at Employee.newemp.access$100(newemp.java:10)
    at Employee.newemp$2.actionPerformed(newemp.java:72)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.jav a:6505)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3321)
    at java.awt.Component.processEvent(Component.java:627 0)
    at java.awt.Container.processEvent(Container.java:222 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4861)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719 )
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:723)
    at java.awt.EventQueue.access$200(EventQueue.java:103 )
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:696)
    at java.awt.EventQueue$4.run(EventQueue.java:694)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 693)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:91)
    BUILD SUCCESSFUL (total time: 10 seconds)

    [/code]
    to get highlighting and preserve formatting.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Run Time Error!!!

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Employee.newemp.addActionPerformed(newemp.java:144 )
    There is a variable with a null value when the code at line 144 is executed. Look at line 144, find the variable with the null value and then backtrack in the code to see why that variable does not have a valid non-null value. Use a println to print out the variables on line 144 if you can not see which variable has the null value.


    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. run time error
    By nayeemohamed in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 6th, 2012, 04:33 PM
  2. Run Time Error
    By Tanmaysinha in forum What's Wrong With My Code?
    Replies: 22
    Last Post: March 8th, 2012, 11:29 AM
  3. Help with run time error
    By white97 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: August 11th, 2011, 12:35 PM
  4. Run Time Error.
    By seymour001 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 10th, 2011, 12:10 PM
  5. [SOLVED] Run time error
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2011, 11:05 AM

Tags for this Thread