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?

Member Avatar for coil

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.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.