• 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

Operand trouble!

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Help! I'm losing my mind. For some reason this code is not working correctly and I think it has something to do with the operands. It's a pretty simple mouse event that tries to verify the password and username against a database result. Can you help me? Thanks in advance.
Craig Snowbarger

[This message has been edited by Sean MacLean (edited March 20, 2001).]
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe your problem is that you are comparing strings using '=='. Since a string is an object, '==' compares if the references to the string are equal.
What you need to use is String.equals() as in :
if ( pass.equals( p ) ) .....
This will compare the contents and not the references. I hope this is clear.
p.s. for not equals you would put
if ( !pass.equals( p )) .....
[This message has been edited by tony hutcheson (edited March 20, 2001).]
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
You need to use the String method compareTo( String ) rather than using the == operator
eg
if( pass.compareTo( p ) == 0 )
this method returns 0 if the two strings contain equivalent character arrays
Dave
 
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look like one problem is that you are doing you String comparison as Objects.
if( pass == p ) {...}
I'm pretty sure you want to do this
if( pass.equals( p ) ) {....}
This just might do the trick.
Sean
 
Sean MacLean
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like I'm the slowest typist - Sean
 
Craig Snowbarger
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all very much. That helped for the operand problems, but now I'm having trouble getting my if statement nested in my while statement to run. My first if statement will if it is true, but if it is false, it won't pass to the consecutive else if statement. (Refer to code above).
Thanks,
Craig Snowbarger
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you really wanted to, you could do
else if (!pass.equals(p)
but if you think about it, by the time you reach the else part of that if/else statement you have already confirmed that pass is not equal to p, so you don't need to check it again. It would be simpler to do
if (pass.equals(p)
{
// some work
{
else // pass not equal to p
{
// some other work
}

Originally posted by Craig Snowbarger:
Thank you all very much. That helped for the operand problems, but now I'm having trouble getting my if statement nested in my while statement to run. My first if statement will if it is true, but if it is false, it won't pass to the consecutive else if statement. (Refer to code above).
Thanks,
Craig Snowbarger


 
reply
    Bookmark Topic Watch Topic
  • New Topic