I've spent hours trying to figure out why some of the fields from a document in Firestore won't transfer to my code.
Can you please help me to identify what's wrong with my code and how I should change it to make it work?
This is what my Firebase Database looks like
(And yes, the bus numbers are purposely saved as Strings)
I was trying to use the getValue method to read the data from Firebase as shown in the code below:
DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("BusDrivers");
// Getting all of the registered bus drivers' information
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot datasnapshot) {
for (DataSnapshot snapshot : datasnapshot.getChildren()) {
BusDriver busDriver = snapshot.getValue(BusDriver.class);
busDrivers.add(busDriver);
}
}
However, only some of the fields are transferred to the busDriver object. When I call busDriver.getDriverFirstName(), I accurately get a result...
But when I call busDriver.getAmBusRoute(), I get this for some reason...
Here's the code of the BusDriver class as well.
public class BusDriver {
private final String busDriverID;
private final String amBusRoute;
private final String pmBusRoute;
private final String driverFirstName;
private final String driverMiddleName;
private final String driverLastName;
public BusDriver() {
this.busDriverID = "N/A";
this.amBusRoute = "N/A";
this.pmBusRoute = "N/A";
this.driverFirstName = "N/A";
this.driverMiddleName = "N/A";
this.driverLastName = "N/A";
}
public BusDriver(String busDriverID, String amBusRoute, String pmBusRoute, String driverFirstName, String driverMiddleName,
String driverLastName) {
this.busDriverID = busDriverID;
this.amBusRoute = amBusRoute;
this.pmBusRoute = pmBusRoute;
this.driverFirstName = driverFirstName;
this.driverMiddleName = driverMiddleName;
this.driverLastName = driverLastName;
}
public String getBusDriverID() { return busDriverID; }
public Object getAmBusRoute() { return amBusRoute; }
public Object getPmBusRoute() { return pmBusRoute; }
public String getDriverFirstName() { return driverFirstName; }
public String getDriverMiddleName() { return driverMiddleName; }
public String getDriverLastName() { return driverLastName; }
}
Please help me. Thank you!

