Hello I am new to android java codding I created a "login activity" and "Users class" and my condition is to add a number of users and pass to the "Users class" and check if the password given is correct then log in, however, it works correctly when I put the right password but if the password is wrong the app just crashes and the if-else condition does not run.
public class MainActivity extends AppCompatActivity {
private EditText Name;
private EditText Password;
private TextView Loginmsg;
public Button Btlogin;
public static int Counter;
public static ArrayList <User> mUsers;
public static int Tester;
private String nameHolder;
private String passHolder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Name = findViewById(R.id.etpsudo);
Password = findViewById(R.id.etpaswword);
Loginmsg = findViewById(R.id.txtlog);
Btlogin = findViewById(R.id.btnlogin);
Tester=0;
Btlogin.setOnClickListener(new View.OnClickListener() {
@SuppressLint("SetTextI18n")
@Override
public void onClick(View v) {
nameHolder=Name.getText().toString();
passHolder=Password.getText().toString();
for(int i=0; i<=mUsers.size();i++){
if((nameHolder.equals(mUsers.get(i).getmNom()))&&(passHolder.equals(mUsers.get(i).getmPass()))){
Counter=i;
i=mUsers.size()+1;
Tester=1;
}
}
if (Tester==1){
Intent drawless = new Intent(MainActivity.this,newacc.class);
startActivity(drawless);
}
else{
Loginmsg.setText("eroor");
}
}
});
mUsers = new ArrayList<>();
mUsers.add(new User("amine","12345"));
mUsers.add(new User("bouhali","4523"));
mUsers.add(new User("khawla","ae12"));
}
}