Recyclerview No Adapter Attached; Skipping Layout

recyclerview No adapter attached; skipping layout

Can you make sure that you are calling these statements from the "main" thread outside of a delayed asynchronous callback (for example inside the onCreate() method).
As soon as I call the same statements from a "delayed" method. In my case a ResultCallback, I get the same message.

In my Fragment, calling the code below from inside a ResultCallback method produces the same message. After moving the code to the onConnected() method within my app, the message was gone...

LinearLayoutManager llm = new LinearLayoutManager(this);
llm.setOrientation(LinearLayoutManager.VERTICAL);
list.setLayoutManager(llm);
list.setAdapter( adapter );

E/RecyclerView: No adapter attached; skipping layout for Recycler View in Kotlin Android Project

The view used in creating the recycler view is not same as the view returned
You created a view and that was used to initialize the recycler view,

  var view = inflater?.inflate(R.layout.fragment_impressions, container, false)

instead of returning this same view above you created another view and returned it.

 return inflater.inflate(R.layout.fragment_impressions, container, false)

so the view used in initializing the recycler view is invalid and the recycler view, therefore invalid also.

ERROR ANDROID STUDIO E/RecyclerView: No adapter attached; skipping layout

Try to follow the approach:

  1. Create an empty adapter the same time you set LayoutManager for the RecyclerView: Save it as field of your Fragment:
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
userAdapter= new UserAdapter(getContext(), new ArraysList<>(), true);
recyclerView.setAdapter(userAdapter);

  1. When data is ready, populate the adapter and notify:
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
/// origin code here

// reset data in adapter and not re-creating adapter:
userAdapter.setItems(mUsers);
getActivity().runOnUiThread(() -> userAdapter.notifyDataSetChanged());
// instead of userAdapter= new UserAdapter(getContext(), mUsers, true); recyclerView.setAdapter(userAdapter);
}

Kotlin E/RecyclerView: No adapter attached; skipping layout

  1. there is no setting of recyclerView var (use findViewById(R.id.yourOwnRecycler) or ViewBinding)
  2. all code accessing views have to be inside onViewCreated
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

recyclerView = view.findViewById(R.id.yourOwnRecycler)

recyclerView?.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)

recyclerView?.adapter = feedAdapter

eventChangeListener()
}


Related Topics



Leave a reply



Submit