'Cannot populate Google Maps with Markers generated from my Firebase Database on Android Studio

This is the code I have for displaying Markers related to my user in my db.

```   dbRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot s : dataSnapshot.getChildren()){
                Users users = s.getValue(Users.class);
                LatLng location = new 
         LatLng(Double.parseDouble(users.longitude),Double.parseDouble(users.latitude));
                mGoogleMap.addMarker(new 
       MarkerOptions().position(location).title(users.name).icon(BitmapDescriptorFactory
                        .defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
                mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(location));

            }
        }```

The error is below

 ``` com.google.firebase.database.DatabaseException: Can't convert 
  object 
  of type java.lang.String to type 
  com.example.newandroidapplication.Users 
```

I found a forum saying to remove the loop which I did. However a further error occurs... java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference

Database Structure

This is the Users Class. I have defined all the attributes with relevant getters and setters. I have generic string values defined in my sign up page to populate longitude and latitude. However once I resolve this error I would like to add in random generated vales.


    public class Users {
    String email, name, studentId,course, password, cpassword;
    String uid;
    String imageUri;
    String status;
    public String longitude;
    public String latitude;


    public Users(String uid, String studentId,String name,String 
  email, String course, String password, String cpassword, String 
  imageUri, String status, String longitude, String latitude) {
        this.uid= uid;
        this.studentId = studentId;
        this.name = name;
        this.email = email;
        this.course= course;
        this.password = password;
        this.cpassword = cpassword;
        this.imageUri= imageUri;
        this.status= status;
        this.longitude = longitude;
        this.latitude= latitude;
    }

The database reference is as follows dbRef= FirebaseDatabase.getInstance().getReference("Users");

I got this code from https://medium.com/@bhavitkanthalia16/multiple-markers-on-map-using-firebase-database-a1181f6f0d52.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source