java - NullPointerException when setting text of text field -


can please me because have project in end of tomorrow?

every time try , set text of text field program crashes , gives null pointer exception. how can overcome this?

here sample code error occurred:

package disciplinesys;  public class newjframe extends javax.swing.jframe {      /** creates new form newjframe */     public newjframe() {         jtextfield1.settext("yes");         initcomponents();     }      @suppresswarnings("unchecked")     // <editor-fold defaultstate="collapsed" desc="generated code">     private void initcomponents() {          jtextfield1 = new javax.swing.jtextfield();          setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close);          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(120, 120, 120)                 .addcomponent(jtextfield1, javax.swing.grouplayout.preferred_size, 139, javax.swing.grouplayout.preferred_size)                 .addcontainergap(141, short.max_value))         );         layout.setverticalgroup(             layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)             .addgroup(layout.createsequentialgroup()                 .addgap(116, 116, 116)                 .addcomponent(jtextfield1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)                 .addcontainergap(164, short.max_value))         );          pack();     }// </editor-fold>      /**     * @param args command line arguments     */     public static void main(string args[]) {         java.awt.eventqueue.invokelater(new runnable() {             public void run() {                 new newjframe().setvisible(true);             }         });     }      // variables declaration - not modify     private javax.swing.jtextfield jtextfield1;     // end of variables declaration  } 

call jtextfield1.settext("yes"); after initcomponents();

like this:

/** creates new form newjframe */ public newjframe() {     initcomponents();     jtextfield1.settext("yes"); } 

this because textfield variable isn't created until initcomponents();


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -