'I am trying to extract data from database in string

   @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //inflate layout (row_user.xml)
        //viewGroup symbol cant be found, in the tutorial below he doesnt have it anywhere
        View view = LayoutInflater.from(context).inflate(R.layout.row_users, viewGroup, false);


        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        //get data
      

        String userImage = usersList.get(i).getImage();
//i appears red for some reason, symbol not //found
        String userName = usersList.get(i).getPseudonym();
       String userPractic = usersList.get(i).getPractic();
        String userType = usersList.get(i).getType();

I've been following this tutorial until now, he doesn't have any problem. It is so weird that he is able to do that without problem.

https://www.youtube.com/watch?v=nRGZchw5z7s

Also the "dataSnapshot" appears red, I guess it has to be changed to "snapshot"

 @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                usersList.clear();
                for (DataSnapshot ds: dataSnapshot.getChildren()) {
                    ModelUsers modelUser = ds.getValue(ModelUsers.class);
                    //get all users except
                    if (!modelUser.getUid().equals(fUser.getUid())) {
                        usersList.add(modelUser);
                    }
                    adapterUsers = new AdapterUsers(getActivity(), usersList);
                    //set adapter to recycler view
                    recyclerView.setAdapter(adapterUsers);
                }
            }

I get this in logcat:

2020-12-17 20:10:32.300 13692-13692/com.android.yoganetworks W/ClassMapper: No setter/field for email found on class com.android.yoganetwork.ModelUsers 2020-12-17 20:10:32.300 13692-13692/com.android.yoganetworks W/ClassMapper: No setter/field for realname found on class com.android.yoganetwork.ModelUsers 2020-12-17 20:10:32.305 13692-13692/com.android.yoganetworks W/ClassMapper: No setter/field for name found on class com.android.yoganetwork.ModelUsers 2020-12-17 20:10:32.305 13692-13692/com.android.yoganetworks W/ClassMapper: No setter/field for profileStatus found on class com.android.yoganetwork.ModelUsers 2020-12-17 20:10:32.305 13692-13692/com.android.yoganetworks W/ClassMapper: No setter/field for email found on class com.android.yoganetwork.ModelUsers 2020-12-17 20:10:32.305 13692-13692/com.android.yoganetworks W/ClassMapper: No setter/field for realname found on class com.android.yoganetwork.ModelUsers 2020-12-17 20:10:32.305 13692-13692/com.android.yoganetworks W/ClassMapper: No setter/field for profileStatus found on class com.android.yoganetwork.ModelUsers 2020-12-17 20:10:32.305 13692-13692/com.android.yoganetworks W/ClassMapper: No setter/field for email found on class com.android.yoganetwork.ModelUsers 2020-12-17 20:10:32.305 13692-13692/com.android.yoganetworks W/ClassMapper: No setter/field for realname found on class com.android.yoganetwork.ModelUsers Blockquote

Here is my ModelUsers

package com.android.yoganetwork;

public class ModelUsers {

//use same name as in firebase database
String pseudonym, practic, type, diet, image, cover, uid;


public ModelUsers() {

}

public ModelUsers(String pseudonym, String practic, String type, String diet, String image, String cover, String uid) {
    this.pseudonym = pseudonym;
    this.practic = practic;
    this.type = type;
    this.diet = diet;
    this.image = image;
    this.cover = cover;
    this.uid = uid;
}

public String getPseudonym() {
    return pseudonym;
}

public void setPseudonym(String pseudonym) {
    this.pseudonym = pseudonym;
}

public String getPractic() {
    return practic;
}

public void setPractic(String practic) {
    this.practic = practic;
}

public String getType() {
    return type;
}

public void setType(String type) {
    this.type = type;
}

public String getDiet() {
    return diet;
}

public void setDiet(String diet) {
    this.diet = diet;
}

public String getImage() {
    return image;
}

public void setImage(String image) {
    this.image = image;
}

public String getCover() {
    return cover;
}

public void setCover(String cover) {
    this.cover = cover;
}

public String getUid() {
    return uid;
}

public void setUid(String uid) {
    this.uid = uid;
}

}


And JSON of my database

    {
  "Users" : {
    "Az7EiIgHSTUobarMFdncbv" : {
      "cover" : "",
      "diet" : "veggies",
      "email" : "[email protected]",
      "image" : "",
      "practic" : "",
      "pseudonym" : "",
      "realname" : "",
      "type" : "",
      "uid" : "Az7EiIgHSTURtJrMFdncbv"
    },
    "NkxX9tzcXsOTn0LeLVuPQfzCGjG2" : {
      "cover" : "https://firebasestorage.googleapis.com/v0/b/database-de88e.appspot.com/o/Users_Profile_Cover_Imgs%2Fcover_NkxX9tzcXsOTn0LeLfzCGjG2?alt=media&token=5f46be85-d333-4ef6-b947-70f5f23a1",
      "diet" : "Vegetariano",
      "email" : "[email protected]",
      "image" : "https://image.shutterstock.com/image-photo/silhouette-palm-trees-sunset-vintage-600w-415974139.jpg",
      "name" : "ACACACAAAAA",
      "practic" : "Yoga Kundalini",
      "profileStatus" : "PRACTICA",
      "pseudonym" : "asdasdasda",
      "realname" : "Sasha",
      "type" : "Instructor",
      "uid" : "NkxX9tzcXsOThfgh5LVuPQfzCGjG2"
    },
    "wDP3jpUoXcdjdsgge4CVDAMFThiCb2" : {
      "cover" : "",
      "diet" : "",
      "email" : "[email protected]",
      "image" : "",
      "practic" : "",
      "profileStatus" : "ffsdhhh",
      "pseudonym" : "",
      "realname" : "asdasd",
      "type" : "",
      "uid" : "wDP3jpUoXcdj5ffCCVDAMFThiCb2"
    }
  }
}


Only a couple users appear on the users fragment. I hope you can help me because I'm really stuck


Solution 1:[1]

Solution was to: Declare in public class private Object ViewGroup; then View view = LayoutInflater.from(context).inflate(R.layout.row_users, (android.view.ViewGroup) ViewGroup, false); In strings instead of "i" index, put position: String userImage = usersList.get(position).getImage(); And for the last one, instead of "dataSnapshot" in for (DataSnapshot ds: dataSnapshot.getChildren()), put only "snapshot": for (DataSnapshot ds: snapshot.getChildren())

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 OneKe