0

The following code written in netbeans it shows error as cannot find length() method and invert if.im new to netbeans. please correct my code.thanks in advance.

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
       if(jTextField1.getText().trim().length() == 0 && jPasswordField1.getPassword().length() == 0)
Andrew Thompson
  • 163,965
  • 36
  • 203
  • 405

2 Answers2

2

getPassword() returns char[] so use .length field

jPasswordField1.getPassword().length

Also See

Community
  • 1
  • 1
jmj
  • 225,392
  • 41
  • 383
  • 426
  • that method is depricated, see http://stackoverflow.com/questions/8881291/why-is-char-preferred-over-string-for-passwords why it is preferred to use getPassword() instead – jmj Sep 05 '13 at 06:00
1

Try

jPasswordField1.getPassword().length

getPassword() returns char[]. See docs.

Alex
  • 10,998
  • 6
  • 34
  • 52