0
public class Signup2 extends javax.swing.JFrame {

/**
 * Creates new form Signup2
 */
public Signup2() {
    initComponents();
}

@SuppressWarnings("unchecked")


private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {                                     


    int i=jTable1.getSelectedRow();
    TableModel m=jTable1.getModel();
    String reference_number;
    reference_number=m.getValueAt(i,1).toString();
    int no=0;
    int n=0;String stm="";
     try{
        Class.forName("java.sql.DriverManager");
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/google_email","root","root");
        Statement st=con.createStatement();
        String q="select message,subject from message where reference_num='"+reference_number+"';";
        ResultSet rs=st.executeQuery(q);


              while(rs.next()){
                  readmessage.jTextField1.setText(rs.getString("Subject"));
                  readmessgae.jTextArea1.setText(rs.getString("message"));
              }


     }

      catch(Exception e){  
       System.err.println(e);

     }


   dispose();
   readmessage rm=new readmessage();
   rm.setVisible(true);




}                                    

readmessage is the name of the jFrame

There is an error in this code in jtable1MouseClicked event. Actually, it's throwing a NullPointerException in the code:

jTextField1.setText("subject"); 
jTextArea1.setText("message");

Instead of setting in a field or area I just printed it and it worked. What is the possible reason for the error and how can I solve it?

error: java.lang.NullPointerException at Signup2.jTable1MouseClicked(Signup2.java:182) at Signup2.access$100(Signup2.java:19) at Signup2$2.mouseClicked(Signup2.java:69) at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270) at java.awt.Component.processMouseEvent(Component.java:6536) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6298) at java.awt.Container.processEvent(Container.java:2237) at java.awt.Component.dispatchEventImpl(Component.java:4889) at java.awt.Container.dispatchEventImpl(Container.java:2295) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4889) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4467) at java.awt.Container.dispatchEventImpl(Container.java:2281) at java.awt.Window.dispatchEventImpl(Window.java:2746) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Arun
  • 1
  • 1
  • 1
    If you can edit your question and provide a proper problem statement, including where the error is happening and what you have done to fix it, then someone may reopen this question. – Tim Biegeleisen May 07 '18 at 13:48
  • 1
    What is the value of `jTextField1` when the exception is thrown? You may want to use a debugger to find out. – Thorbjørn Ravn Andersen May 07 '18 at 13:50
  • This was the error thrown "java.lang.NullPointerException" and i just replace the setText() method with standard output and it worked. I figured out the problem is with the setText() method that throws the problem – Arun May 07 '18 at 14:11

0 Answers0