This isn't a problem, just a curious question. I'm using the password text field in my gui and basically, this:

String pin = new String(passwordField.getPassword());
Person p = new Person();
p.setPassword(Integer.parseInt(pin));

leads to a number format error, despite that I didn't enter a text. But this:

String pin = new String(passwordField.getPassword());
int pn = Integer.parseInt(pin)
Person p = new Person();
p.setPassword(pn);

works. Why? Aren't they the same?

Are you sure you entered the same thing? Even if you typed in a space, that could trigger an error.

Hi coil, if you typed a space, both would trigger errors, which is normal, as we don't want people entering spaces anyway. If you typed an int, the first one would trigger an error. The second wouldn't. That's what im seeing right now.

Edited 6 Years Ago by glenak: n/a

To debug your code add a println() to show the value before you try to parse it.
println("pin=" + pin + "<") // show pin's value

a number format error

Can you post the full text of the error message here?

Edited 6 Years Ago by NormR1: n/a

This question has already been answered. Start a new discussion instead.