Fabio Nobre Fabio Nobre - 1 year ago 59
Android Question

Why does my child with space does not work in firebase?

My database is this ->

"140107": {
"Guest First Name": "As",
"Guest Last Name": "Rodrigues",
"Email": "aaa@yahoo.com.br",
"Country": "Brazil",
"Check-In date": "11-Jun-2016",
"Check-Out date": "12-Jun-2016",
"Room": "Cama Casal com suite",
"Unit No": 1,
"Subtotal": 90,
"Revenue": 90,
"Currency": "BRL",
"Create Date": "19-May-2016"

My code is this

public void ProcuraReservaporemail(){
String email = FirebaseAuth.getInstance().getCurrentUser().getEmail();
myRef = database.getReference("reserva/");
myRef.orderByChild("Email").equalTo(email).addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
// Reserva reserva1;
for(DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
// reserva1 = new Reserva(childSnapshot);

String Unit = (String) childSnapshot.child("Unit No").getValue();
textview2.setText( childSnapshot.child("Unit No").getValue(String.class));

The instruction
childSnapshot.child("Unit No").getValue(String.class)
generates an error because my bank with this space.I would have to change that so that this error does not happen anymore? I thought about changing all my bank more and more work.Do not have a specific error for the Activity stopped working.

Answer Source

Try using:

(String) childSnapshot.child("Unit No").getValue()


String.valueOf(childSnapshot.child("Unit No").getValue())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download