-2

In a jFrame im trying to verify if the user forget to write a password, but when i try to:

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        try {
            char[] pass = jPass.getPassword();
            if(pass.length == 0){
                //continue with the proces
            }
            //or:
            //if(pass == null)
        } catch (Exception e) {
            //some Warning
        }
    }      

The program just CRASHES and i have to use the Task Manager from Windows to close it. How can i know if the user forgot to write his password?.

(YES, i wanna use a char[] because that how you have to use

getPassword()

)

Ulkra
  • 13
  • 5
  • 1
    Can you please post a [MCVE]? Your code will not compile, and the error could very well be anywhere else, as `pass.length` will work. – Ken Y-N Mar 16 '18 at 05:58
  • Okay, done, idk what is wrong with the code, YES, MAYBE is the pass.length, can you understand it now? – Ulkra Mar 16 '18 at 06:06
  • I see nothing wrong with your code providing you are indeed using the **JPasswordField** component. You shouldn't need the **try/catch** either. Something else in code must be causing your issue. – DevilsHnd - 退職した Mar 16 '18 at 06:35
  • Bro, when i try that and i put nothing in the jPasswordField IT DOENS´T throw an error, it just crashed (is hard to do this in Java) as i say it in the question. Just me? – Ulkra Mar 16 '18 at 06:39

1 Answers1

0

That's the closest I've found. Hope that helps.

if (Arrays.equals(password.getPassword(), new char[{'p','a','s','s','w','o','r','d'}]))

getText() vs getPassword().

Read up pa little here for there's a few interesting responses.