By the title of this question, its easily understandable that, the adapter of recyclerview is not set inside a UI thread. But in my case to avoid that I have tried doing it even on UI thread but still no luck.
I am using FirebaseUI for my app. Below is the code snippet:
public static void getUserFromUserId(@NonNull DatabaseReference dbRef, @NonNull String userId) { dbRef.child(USERS).child(userId) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { User user = dataSnapshot.getValue(User.class); FriendsActivity.this.runOnUiThread(new Handler() { @Override public void run() { loadFriends(user); } }); } @Override public void onCancelled(DatabaseError databaseError) { FirebaseCrash.report(databaseError.toException()); } }); } private void loadFriends(User user) { Query friendsRef = ; // your firebase DatabseReference path FirebaseRecyclerAdapter<Friend, FriendViewHolder> adapter = new FirebaseRecyclerAdapter<Friend, FriendViewHolder>(Friend.class, R.layout.item_challenge, FriendViewHolder.class, friendsRef) { @Override protected void populateViewHolder(FriendViewHolder viewHolder, Friend model, int position) { viewHolder.setFriendName(model.getName()); viewHolder.setFriendPic(FriendActivity.this, model.getProfilePic()); } }; mRecyclerView.setAdapter(adapter); }
My Activity's onCreate() method has below code related to RecyclerView:
mRecyclerView = (RecyclerView) findViewById(R.id.challenge_recycler_view); mRecyclerView.setHasFixedSize(true); LinearLayoutManager layoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(layoutManager);
I dont understand why even after calling loadFriends
inside runOnUiThread
, why the error still persists.
Any help is appreciated.