Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Dark

Thread: If statement not working right

  1. #1
    Andrew_3ds is offline Member
    Join Date
    Sep 2013
    Posts
    13
    Rep Power
    0

    Default If statement not working right

    For some reason even if I type in the correct data I still get the error message. The system also prints out the correct data typed in.
    -------------------------------------------------------------------------------------------------------------------------------

    Java Code:
    public void actionPerformed(ActionEvent arg0) {
    				String uText = textField.getText();
    				System.out.print(uText);
    				String pText = passwordField.getText();
    				System.out.println(" : "+pText);
    				
    				if (uText == "user" && pText == "pass") {
    				JOptionPane.showMessageDialog(null, "Successfully legged in", "Loggin", JOptionPane.INFORMATION_MESSAGE);
    				}else {
    					JOptionPane.showMessageDialog(null, "Incorrect Data.\nPlease try again.", "Error", JOptionPane.ERROR_MESSAGE);
    				}
    Last edited by Andrew_3ds; 10-02-2013 at 02:35 AM.

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: If statement not working right

    What is your error message?
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  3. #3
    Andrew_3ds is offline Member
    Join Date
    Sep 2013
    Posts
    13
    Rep Power
    0

    Default Re: If statement not working right

    Quote Originally Posted by Dark View Post
    What is your error message?
    I don't get a console error message, my JOptionPane error message appears, it is not reading the textField.getText() for some reason. I have it so if the username and password are incorrect is makes JOptionpane error message, but even if you type in the correct username and password it still gives you the error message.

  4. #4
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: If statement not working right

    Oh, I see. You are using "==" instead of .equals().
    Andrew_3ds likes this.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  5. #5
    Andrew_3ds is offline Member
    Join Date
    Sep 2013
    Posts
    13
    Rep Power
    0

    Default Re: If statement not working right

    Quote Originally Posted by Dark View Post
    Oh, I see. You are using "==" instead of .equals().
    Thank you!

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,770
    Rep Power
    5

    Default Re: If statement not working right

    Quote Originally Posted by Andrew_3ds View Post
    Thank you!
    "Thank you I no longer have an error", or "thank you I understand what the problem was" ?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Why is my if statement not working.
    By OverRatedProgrammer in forum New To Java
    Replies: 4
    Last Post: 08-23-2013, 04:31 AM
  2. Why isn't this if statement working?
    By ocomobock in forum New To Java
    Replies: 3
    Last Post: 03-27-2012, 02:13 AM
  3. 'if' statement not working?
    By Etimer in forum New To Java
    Replies: 4
    Last Post: 03-10-2012, 05:18 AM
  4. SQL statement working in one class but not another
    By Dcalladi in forum New To Java
    Replies: 4
    Last Post: 11-11-2011, 01:35 AM
  5. Update statement not working.
    By OMFGITSROHIT in forum JDBC
    Replies: 5
    Last Post: 04-08-2010, 01:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •