• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JOption --- Password

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My pleasure
 
That new kid is a freak. Show him this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic