1
I have to authenticate the user, but when I inform the user and the correct password he enters the menu screen, so far so good. The problem is that when I type an incorrect password or user, I want to present a message user not found, the problem is that when it is to appear Toast with the message the app to.
Search method in the bank
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;
}
Method Login button
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
Show the
Logcat
, please.– itscorey
Follows above in the post
– alannrs
CursorIndexOutOfBoundsException: index 0 requested, with a size of 0
– itscorey