Ad

Firestore Recycler Not Showing Any Results On App Screen With No Errors

I want to make a chore app using a firebase that has 2 inputs: Description and class. Whenever I run the app, the screen that shows is blank (except for the header) There is no clear indication or errors that might show the problem. These are the most fruitful logCat log areas:

2019-07-12 16:42:37.306 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for length found on class com.example.choretest.Chores
2019-07-12 16:42:37.306 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for description found on class com.example.choretest.Chores
2019-07-12 16:42:37.307 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for length found on class com.example.choretest.Chores
2019-07-12 16:42:37.307 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for description found on class com.example.choretest.Chores
2019-07-12 16:42:37.307 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for length found on class com.example.choretest.Chores
2019-07-12 16:42:37.308 5300-5300/? W/Firestore: (20.1.0) [CustomClassMapper]: No setter/field for description found on class com.example.choretest.Chores

2019-07-12 16:43:47.301 5300-5385/com.example.choretest V/FA: Inactivity, disconnecting from the service

I have tried checking to make sure all the names of the collections and documents were consistent since I have no other leads.

Main activity:

private RecyclerView mMainList;
private static final String TAG = "MainActivity";

public FirebaseFirestore mFirestore;

private ChoresListAdapter ChoresListAdapter;

private List<Chores> choreList;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMainList = (RecyclerView) findViewById(R.id.main_list);
    mFirestore = FirebaseFirestore.getInstance();
    choreList = new ArrayList<>();
    ChoresListAdapter = new ChoresListAdapter(choreList);
    mMainList.setHasFixedSize(true);
    mMainList.setLayoutManager(new LinearLayoutManager(this));
    mMainList.setAdapter((ChoresListAdapter));


    mFirestore.collection("choreList").addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
            if(e != null){
                Log.d(TAG, "ERROR: " + e.getMessage());
            }

            for(DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()){
                if(doc.getType() == DocumentChange.Type.ADDED){
                    Chores chores = doc.getDocument().toObject(Chores.class);
                    choreList.add(chores);

                    ChoresListAdapter.notifyDataSetChanged();


                }
            }


        }
    });
}

Secondary Chores class:

String chore, time;

public Chores(){

}

public Chores(String chore, String time) {
    this.chore = chore;
    this.time = time;
}

public String getChore() {
    return chore;
}

public void setChore(String chore) {
    this.chore = chore;
}

public String getTime() {
    return time;
}

public void setTime(String time) {
    this.time = time;
}

Adapter for the recyclerview:

public List<Chores> choreList;

public ChoresListAdapter(List<Chores> choreList){
    this.choreList = choreList;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
    return  new ViewHolder(view);

}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    holder.lengthText.setText(choreList.get(position).getTime());
    holder.descriptionText.setText(choreList.get(position).getChore());
}

@Override
public int getItemCount() {
    return choreList.size();
}

public class ViewHolder extends RecyclerView.ViewHolder{
    View mView;

    public TextView descriptionText;
    public TextView lengthText;


    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        mView = itemView;

        descriptionText = (TextView) mView.findViewById(R.id.description_text);
        lengthText = (TextView) mView.findViewById(R.id.length_text);
    }
}

I expect the output to be a list of the messages on the firestore collection, but instead, there is only a blank screen.

Ad

Answer

The problem is that the name of the fields in your Chores class are different than the names that exist in the database. To solve this you should change the property names of chore and time in your model class to description and lenght or you should change the name in the database to match the names in your model class.

Another workaround might be to use annotations. You can make your fields public and add in front of each fields the following annotations:

@PropertyName("description")
public String chore;
@PropertyName("lenght")
public String time

So remember, all the fieds names in your models class must match the one that exist in the database.

Ad
source: stackoverflow.com
Ad