Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android RecyclerView LayoutManager Exception

Hi I'm having an issue with the new Android Lollipop RecyclerView

It keeps crashing with the following exception:

Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView$LayoutManager.onMeasure(android.support.v7.widget.RecyclerView$Recycler, android.support.v7.widget.RecyclerView$State, int, int)' on a null object reference

Full stack trace can found here

The code used to initiate the RecyclerView is the same mostly the same as the tutorial, however for some reason this still complains. Any help would be greatly appreciated.

The code can be accessed at: gist here and layout: this gist

None of the views, or objects are null

like image 336
Bin power93 Avatar asked Oct 19 '14 00:10

Bin power93


1 Answers

Add the following code:

    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);

Before adding adapter:

recyclerView.setAdapter(adapter);
like image 100
Udi Oshi Avatar answered Sep 29 '22 04:09

Udi Oshi