E/RecyclerView: No adapter attached; skipping layout

2018, Jan 09    

This error is a common error many developers might find if they do a silly mistake. Let’s discuss about the problem:

Problem:

After inflating the RecyclerView into your view class (Activity or Fragment), you should mention the LayoutManager of it. If by mistake you miss it, Android will skip drawing the layout. Lets see the below example with mistake in it:

recyclerView = findViewById(R.id.recycler_view);
adapter = new MyAdapter();
recyclerView.setAdapter(adapter);

Solution:

recyclerView = findViewById(R.id.recycler_view);
LinearLayoutManager manager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(manager);
recyclerView.setHasFixedSize(true);
adapter = new MyAdapter();
recyclerView.setAdapter(adapter);

Since we have set the layout manager for RecyclerView, it should now be able to draw the layout properly.

NOTE: setHasFixedSize(…) has nothing to do with current problem. It is just added in the example as a good practice to make our layout drawing faster.