Reputation: 33
These are steps I am doing in this project:
The ArrayList Activity file:
Initializing the recyclerView in OnCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_journal_list);
firebaseAuth= FirebaseAuth.getInstance();
user= firebaseAuth.getCurrentUser();
noJournalEntry= findViewById(R.id.list_no_thoughts);
journalList= new ArrayList<>();
recyclerView= (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
}
Invoking the RecyclerView in onStart:
@Override
protected void onStart() {
super.onStart();
//we are getting the user Id of the person who is logged in
collectionReference.whereEqualTo("userId", JournalApi.getInstance()
.getUserId())
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if(!queryDocumentSnapshots.isEmpty()) {
for(QueryDocumentSnapshot journals: queryDocumentSnapshots){
Journal journal = journals.toObject(Journal.class);
journalList.add(journal);
Toast.makeText(JournalListActivity.this,"UserId found", Toast.LENGTH_LONG).show();
}
// Invoke Recyclerview
journalRecyclerAdapter= new JournalRecyclerAdapter(JournalListActivity.this, journalList);
recyclerView.setAdapter(journalRecyclerAdapter);
journalRecyclerAdapter.notifyDataSetChanged();
} else {
noJournalEntry.setVisibility(View.VISIBLE);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(JournalListActivity.this,"UserId NOT found", Toast.LENGTH_LONG).show();
}
});
}
}
As you can see that the RecyclerView is called fine, but the ArrayList is not loading.
The Error: E/RecyclerView: No adapter attached; skipping layout
I referred to various posts in Stackoverflow and followed the steps, not sure where I am going wrong.
I am adding screenshots here of the Arraylist file:
Upvotes: 1
Views: 227
Reputation: 138969
You are getting the following warning, not an error:
E/RecyclerView: No adapter attached; skipping layout
Because you are setting the adapter in a background thread. To solve this, you have to set the adapter outside the callback and inside it, just notify it about the changes. So please move the following lines of code:
journalRecyclerAdapter= new JournalRecyclerAdapter(JournalListActivity.this, journalist);
recyclerView.setAdapter(journalRecyclerAdapter);
Right after:
super.onStart();
And leave the following line as it is inside the callback:
journalRecyclerAdapter.notifyDataSetChanged();
And the warning will disapear.
Upvotes: 1