'When they want to log in my app crashes firebase realtime database [duplicate]
I am using a real-time database (in firebase) and my error is that when trying to enter the account it gives me an error and the application crashes in the case it indicates that the error is that attached the code and one more image clear
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
final EditText et_correo = findViewById(R.id.et_correo);
final EditText et_contrasena = findViewById(R.id.et_contrasena);
final Button btn_ingresar = findViewById(R.id.btn_ingresar);
final TextView btn_registrate = findViewById(R.id.btn_registrate);
btn_ingresar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String correotxt = et_correo.getText().toString();
final String contrasenaTxt = et_contrasena.getText().toString();
if (correotxt.isEmpty() || contrasenaTxt.isEmpty()) {
Toast.makeText(LoginActivity.this, "Favor de introducir sus datos", Toast.LENGTH_SHORT).show();
} else {
databaseReference.child("nombre").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
//THIS IS MY ERROR
if (snapshot.hasChild(correotxt)) {
final String getPassword = snapshot.child(correotxt).child("contrasena").getValue(String.class);
if (getPassword.equals(contrasenaTxt)) {
Toast.makeText(LoginActivity.this, "Se ha logueado de manera exitosa!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
}else{
Toast.makeText(LoginActivity.this, "Correo o Contraseña incorrectos", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
btn_registrate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// open RegistroActivity
startActivity(new Intent(LoginActivity.this, RegistroActivity.class));
}
});
}
}
});}}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
