• Post Reply Bookmark Topic Watch Topic
  • New Topic

JOption --- Password  RSS feed

 
Ray Garcia
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I'm new to the site and already have a question regarding java.

The goal of this section of my assignment is to ask the user for a password. The password entered has to match the password I set in the code. If it is correct the next dialog box will pop up.

my password is set to:
String enterpwd = "";
String correctPassword = "Setpassword";


I am asked to use JOption, I completed as follows:

enterpwd = JOptionPane.showInputDialog(""............JOptionPane.QUESTION_MESSAGE);

then I use IF statements

if (enterpwd == correctPassword)
xyz = JOption .......();




I hope this is enough information. I am getting an error "java.lang.NumberFormatException: For input string: """


Help would greatly be appreciated. I will come back and give more detail if this is not enough (im currently at work, rushed this).
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

There's no code shown which can throw a NumberFormatException, please paste in the code you are running and the full error message and stack trace.

BTW you shouldn't compare Strings for equality using ==, you almost always should be using equals().
 
Liutauras Vilda
Sheriff
Posts: 4921
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray,

Did you come up with something? Post it here.
 
Ray Garcia
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony! Using 'equals()' fixed it. I over thought the whole thing.

Thanks for the quick responses!
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!