0

I am trying to make a login screen for my android app. I enter to correct username and password and I get the toast message saying I have the wrong username or password. I've tried everything I can think of to try and fix this and thought I would ask for some help on here.

public void welcomeScreen(View view){
        String userName1 = "student";
        String password1 = "school";
        Intent intent = new Intent(this, WelcomeScreen.class);
        EditText editText1 = (EditText) findViewById(R.id.editText1);
        String userName = editText1.getText().toString();

        EditText editText2 = (EditText) findViewById(R.id.editText2);
        String password = editText2.getText().toString();

        if(userName != userName1 || password != password1){
            Context context = getApplicationContext();
            CharSequence text = "Incorrect Username or Password!";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }

        else startActivity(intent);
    }
2
Contributors
1
Reply
5
Views
5 Years
Discussion Span
Last Post by peter_budo
1

Guess you already solve it since post is marked as solved, but for others never do compare strings as numeric values with == or != always use strin1.equals(string2)

Edited by peter_budo: edit

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.