user1424296
user1424296

Reputation: 61

How to set my username and password in the code.?

Button loginbuttonbutton = (Button) findViewById(R.id.btnLogin);
loginbuttonbutton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        if(inputEmail.getText().toString() == "[email protected]" &&
           inputPassword.getText().toString() == "Steelers") {
            Intent myIntent = new Intent(view.getContext(),
                                         Host_Setting_PageActivity.class);
            startActivityForResult(myIntent, 0);
        } else {
            System.out.println("Username or password is incorrect");
        }
    }
});

That is my code and the application actually start but whenever I hit the login button the application closes.

Upvotes: 0

Views: 2821

Answers (4)

Divyesh Dabhi
Divyesh Dabhi

Reputation: 1

dont use == method in if Condition but used .equals() method like as

if(inputEmail.getText().toString().equals("abc") && inputPassword.getText().toString().equals("abc") ){
----------your code here-----------
}

Upvotes: 0

vanleeuwenbram
vanleeuwenbram

Reputation: 1339

You should add

Host_Setting_PageActivity.class to your AndroidManifest

And also, you should compare strings always using .equals and not with "==" as "==" will really compare the instance of the string object and .equals will check the value of the string

Upvotes: 0

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132972

use equals insead of == for String comparison

    loginbuttonbutton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if(inputEmail.getText().toString().equals("[email protected]") && inputPassword.getText().toString().equals("Steelers") ){
            Intent myIntent = new Intent(YOUR_CURRENT_ACTIVITY.this, Host_Setting_PageActivity.class);
            startActivityForResult(myIntent, 0);
        }
            else{
                System.out.println("Username or password is incorrect");
            }
        }
    });

and make sure you are registering YOUR_CURRENT_ACTIVITY.this and Host_Setting_PageActivity.class both in manifest.xml

Upvotes: 2

Samir Mangroliya
Samir Mangroliya

Reputation: 40406

first use .equals() to compare strings.

== compares string refrences.Not value.

.equals() = compare strings character equality

if((inputEmail.getText().toString().equals("[email protected]")&&inputPassword.getText().toString().equals("Steelers"))

And if force close than put logcat here..

Upvotes: 3

Related Questions