Mohit :
private void validate(String userName, String userPassword){
if((userName == "Admin") && (userPassword == "1234")){
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
} else{
counter --;
Info.setText(userName + " Number of Attempts Left: "+String.valueOf(counter) + " - " + userPassword);
if(counter == 0){
Login.setEnabled(false);
}
}
}
Whenever i give input as "Admin" and "1234" condition goes to else part. please help me i am beginner in this field.
IntelliJ Amiya :
string equals() method compares the two given strings based on the data/content of the string.
Try with
if(userName.equals("Admin") && userPassword.equals("1234")){
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
} else{
counter --;
Info.setText(userName + " Number of Attempts Left: "+String.valueOf(counter) + " - " + userPassword);
if(counter == 0){
Login.setEnabled(false);
}
}