0

When I print out the user value and the pass value into LogCat, the values are printed out as "A" and "a". If the user value is "A" and the pass value is "a", I don't understand why the if statement doesn't execute. When I place the contents that are inside the if statement outside of the if statement, the startActivity() method operates correctly. This tells me that the if statement is the problem but I don't see how. I don't get it!

        public void onClick(View v) 
        {
            String user = username.getText().toString();
            String pass = password.getText().toString();

            System.out.println(user);
            System.out.println(pass);

            if (user == "A" && pass == "a")
            {
                Intent intent = new Intent("com.example.android.STARTINGPOINT");
                startActivity(intent);
            }


        }

1 Answers1

5

Use the String#equals method to compare strings instead of ==:

if (user.equals("A") && pass.equals("a"))
M A
  • 71,713
  • 13
  • 134
  • 174