I am making an application for an inventory of item loans (keyboards, mouse...) I ask for Carrera, name to whom I lend, item, date, received in case they return and status (Loaned or delivered), ok help me out video to make the database with FIREBASE.
The authentication works great but what interests me the most is the database. The application when I give it a registration tells me "Successful registration" but does not save anything.
I would really appreciate the help, please.
(various variables declared)
private DatabaseReference Clases;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prestamo);
Clases = FirebaseDatabase.getInstance().getReference("Clases");
Estudiante = (EditText)findViewById(R.id.edtEstd);
Articulo = (EditText)findViewById(R.id.edtArt);
Recibido = (EditText)findViewById(R.id.edtRecibido);
Fecha = (EditText)findViewById(R.id.edtFecha);
Estado = (Spinner)findViewById(R.id.spnEstado);
btRegistrarP = (Button)findViewById(R.id.btRegistroP);
ayuda = (ImageButton)findViewById(R.id.btnAyuda);
}
public void RegistrarPrestamo(){
String estud = Estudiante.getText().toString();
String artic = Articulo.getText().toString();
String fech = Fecha .getText().toString();
String estado = Estado.getSelectedItem().toString();
String recib = Recibido.getText().toString();
if(!TextUtils.isEmpty(estud)){
String id = Clases.push().getKey();
Clases lai= new Clases(id,estud, artic,fech,estado,recib);
Clases.child(id).setValue(lai);
Toast.makeText(this, "Registro exitoso", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this, "Introduzca un Estudiante", Toast.LENGTH_SHORT).show();
}
}
public void Ayuda(){
Toast.makeText(this, "LLene este cuadrante en caso de estar recibiendo un Artículo", Toast.LENGTH_LONG).show();
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.btRegistroP:
RegistrarPrestamo();
break;
case R.id.btnAyuda:
Ayuda();
}
}
The reference is fine and the code writing and initializing the reference is fine.
It can be for two things
You didn't enable internet permission in your Manifest
You have your Firebase rules for authenticated user write only
On the other hand, in terms of design, I would advise you to use variable names in lower case and not in upper case, you can confuse them with a class or object
As I see that you also have an instance of
Clases
, the problem may be that itClases
is declared asDatabaseReference
, andClases
asClases
, I suggest you change the name of yourDatabaseReference
to lower case as I proposed above .First get the main database reference
Firebase Guide