Sunday, May 17, 2015

Handling adapter error while using RecyclerView in Android

Hello All:

RecyclerView is introduced with Android L and is also available with AppCompat library. RecyclerView provides better layout option and performance as compared to ListView. However, in this post I will share one of the possible solutions to a problem which occurs with RecyclerView.
Often in our application we rely on network data to be populated in our views. With RecyclerView one problem occurs when the data is not available during initialization.

In the logcat, you can often see following error.
recyclerview No adapter attached; skipping layout

One way to fix this issue is to attach an empty adapter to the RecyclerView

    void initializeRecyclerView() {
        recyclerView = (RecyclerView) view.findViewById(;
        recyclerView.setAdapter(new SampleAdapter(getCurrentActivity()));
        recyclerView.setLayoutManager(new LinearLayoutManager(getCurrentActivity()));
Call this method in OnCreateView or OnCreate methods.
Hope this helps. Let me know if you know any other way of fixing the issue.

Thanks for printing this post. Hope you liked it.
Keep visiting and sharing.


  1. Why does this problem occur? any docs supporting this?

  2. this is error should come while using retrofit API

  3. Would this be applicable to volley?

  4. would this be applicable to volley?