I have to perform the authentication of the user, but when I inform the user and the correct password it enters the menu screen, so far so good. The problem is that when I type a bad password or user, I want it to display a user not found message, the problem is that when it is to pop up Toast with the message the app stops.
Bank Search Method
public Usuario UsuarioAutenticar (String user, String senha){
Usuario usuario = new Usuario ();
String autenticarSQL = "SELECT * FROM tblUsuario WHERE usuario = '" + user +"' and senha = '"+senha+"'";
sqLiteDatabase = bancoDados.getWritableDatabase();
Cursor cursor = sqLiteDatabase.rawQuery(autenticarSQL,null);
cursor.moveToFirst();
usuario.setIdUsuario(Integer.parseInt(cursor.getString(0)));
usuario.setNome(cursor.getString(1).toString());
usuario.setCpf(cursor.getString(2).toString());
usuario.setEmail(cursor.getString(3).toString());
usuario.setTelefone(cursor.getString(4).toString());
usuario.setUser(cursor.getString(5).toString());
usuario.setSenha(cursor.getString(6).toString());
return usuario;
}
Login button method
public void btAcessarOnClick (View view) {
usuario = usuarioDAO.UsuarioAutenticar(edUsuario.getText().toString(), edSenha.getText().toString());
if(usuario!=null) {
Intent intent = new Intent(ActivityLogin.this, ActivityMenu.class);
startActivity(intent);
}
else
Toast.makeText(this, "Usuario não encontrado", Toast.LENGTH_SHORT).show();
}
Logcat