title: How to put a recyclerview inside a recyclerView in android
body: <p>so I have a <code>RecyclerView</code> inside a <code>RecyclerView</code>. And I'm getting this error regarding my <code>LayoutManager</code> for the <code>RecyclerView</code>.. The data im working with is a OpenHours object, where Open Hours is a class I made to encapsulate a store's opening and closing hours through the week. The error is pointing to this line in my parent recycler view (which is the first recycler view written on top):</p>
  
  <p><code>recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext()));</code></p>
  
  <p>Here is my class. </p>
  
  <pre><code>public class HoursActivity extends AppCompatActivity
  {
      private RecyclerView rV;
      private TextView addHoursTV;
      private HoursRecyclerViewAdapter hoursRecyclerViewAdapter;
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_hours);
          bindActivity();
      }
      private void bindActivity()
      {
          if(!Global_Class.getInstance().getValue().openHoursArrayList.isEmpty())
          {
              rV = (RecyclerView) findViewById(R.id.activity_hours_RV);
              rV.setLayoutManager(new LinearLayoutManager(getBaseContext()));
              hoursRecyclerViewAdapter = new HoursRecyclerViewAdapter(getBaseContext(),Global_Class.getInstance().getValue().openHoursArrayList);
              rV.setAdapter(hoursRecyclerViewAdapter);
              rV.setItemAnimator(new DefaultItemAnimator());
          }
          addHoursTV = (TextView) findViewById(R.id.activity_hours_addHoursTV);
          addHoursTV.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent i = new Intent(HoursActivity.this,SetHours.class);
                  startActivity(i);
              }
          });
      }
      //An recycler view adapter that can take in multiple views
      public class HoursRecyclerViewAdapter extends RecyclerView.Adapter&lt;HoursRecyclerViewAdapter.MyViewHolder&gt;
      {
          private LayoutInflater inflater;
          private ArrayList&lt;OpenHours&gt; infoList = new ArrayList&lt;&gt;();
          private Context context;
  
          public HoursRecyclerViewAdapter(Context context, ArrayList&lt;OpenHours&gt; data)
          {
              inflater = LayoutInflater.from(context);
              this.infoList = data;
              this.context = context;
          }
          @Override
          public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
          {
              View view = inflater.inflate(R.layout.view_hours,parent,false);
              MyViewHolder holder = new MyViewHolder(view);//special way to avoid "findViewById everytime you make a view
              Log.d("Qamar", "onCreateviewHolder called");
              return holder;
          }
          @Override
          public void onBindViewHolder(MyViewHolder holder, final int position)//onBindViewHolder does all the work.
          {
              HoursTwoRecyclerViewAdapter hoursTwoRecyclerViewAdapter;
              hoursTwoRecyclerViewAdapter = new HoursTwoRecyclerViewAdapter(getBaseContext(),infoList);
              holder.recyclerView.setAdapter(hoursTwoRecyclerViewAdapter);
              holder.recyclerView.setItemAnimator(new DefaultItemAnimator());
          }
          @Override
          public int getItemCount()
          {
              return infoList.size();
          }
          class MyViewHolder extends RecyclerView.ViewHolder
          {
              RecyclerView recyclerView;
              public MyViewHolder(View itemView)
              {
                  super(itemView);
                  recyclerView = (RecyclerView) findViewById(R.id.view_hours_RV);
                  recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext()));
              }
          }
      }
      //An recycler view adapter that can take in multiple views
      public class HoursTwoRecyclerViewAdapter extends RecyclerView.Adapter&lt;HoursTwoRecyclerViewAdapter.MyViewHolder&gt;
      {
          private LayoutInflater inflater;
          private ArrayList&lt;OpenHours&gt; infoList = new ArrayList&lt;&gt;();
          private Context context;
  
          public HoursTwoRecyclerViewAdapter(Context context, ArrayList&lt;OpenHours&gt; data)
          {
              inflater = LayoutInflater.from(context);
              this.infoList = data;
              this.context = context;
          }
          @Override
          public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
          {
              View view = inflater.inflate(R.layout.view_hours_two,parent,false);
              MyViewHolder holder = new MyViewHolder(view);//special way to avoid "findViewById everytime you make a view
              Log.d("Qamar", "onCreateviewHolder called");
              return holder;
          }
          @Override
          public void onBindViewHolder(MyViewHolder holder, final int position)//onBindViewHolder does all the work.
          {
              OpenHours openHours = infoList.get(position);
              holder.dayTV.setText(openHours.getDaysOpen().get(position));
              holder.openingTimeHrTV.setText(openHours.getOpeningHour().substring(0,1));
              holder.openingTimeMinuteTV.setText(openHours.getOpeningHour().substring(2,3));
              holder.closingTimeHrTV.setText(openHours.getClosingHour().substring(0,1));
              holder.closingTimeMinuteTV.setText(openHours.getClosingHour().substring(2,3));
  
          }
          @Override
          public int getItemCount()
          {
              return infoList.size();
          }
          class MyViewHolder extends RecyclerView.ViewHolder
          {
              TextView dayTV,openingTimeHrTV,openingTimeMinuteTV,closingTimeHrTV,closingTimeMinuteTV;
              public MyViewHolder(View itemView)
              {
                  super(itemView);
                  dayTV = (TextView) findViewById(R.id.view_hours_2_day);
                  openingTimeHrTV = (TextView) findViewById(R.id.view_hours_2_openingTimeHour);
                  openingTimeMinuteTV = (TextView) findViewById(R.id.view_hours_2_openingTimeMinute);
                  closingTimeHrTV = (TextView) findViewById(R.id.view_hours_2_closingTimeHour);
                  closingTimeMinuteTV = (TextView) findViewById(R.id.view_hours_2_closingTimeMinute);
  
  
              }
          }
      }
  }
  </code></pre>
  
  <p>And here is my first parent recycler view xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
      &lt;include
          android:layout_height="wrap_content"
          android:layout_width="match_parent"
          layout="@layout/toolbar_layout"&gt;
      &lt;/include&gt;
      &lt;android.support.v7.widget.RecyclerView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/activity_hours_RV"/&gt;
      &lt;android.support.v4.widget.Space
          android:layout_width="match_parent"
          android:layout_height="20dp" /&gt;
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="50dp"
          android:text="Add extra hours"
          android:textColor="@color/green_test"
          android:id="@+id/activity_hours_addHoursTV"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And my child xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="100dp"&gt;
      &lt;android.support.v7.widget.RecyclerView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/view_hours_RV"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Finally here is my log error:</p>
  
  <pre><code>10-14 21:42:26.804 18552-18552/com.daprlabs.aaron.swipedeck2 E/UncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
  at com.daprlabs.aaron.swipedeck2.CardInfo.HoursActivity$HoursRecyclerViewAdapter$MyViewHolder.&lt;init&gt;(HoursActivity.java:97)
  at com.daprlabs.aaron.swipedeck2.CardInfo.HoursActivity$HoursRecyclerViewAdapter.onCreateViewHolder(HoursActivity.java:73)
  at com.daprlabs.aaron.swipedeck2.CardInfo.HoursActivity$HoursRecyclerViewAdapter.onCreateViewHolder(HoursActivity.java:57)
  at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5836)
  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5060)
  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4970)
  at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
  at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
  at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
  at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
  at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
  at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2843)
  at android.view.View.measure(View.java:18834)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5953)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
  at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
  at android.view.View.measure(View.java:18834)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5953)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
  at android.view.View.measure(View.java:18834)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5953)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
  at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
  at android.view.View.measure(View.java:18834)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5953)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  at android.view.View.measure(View.java:18834)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5953)
  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
  at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
  at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
  at android.view.View.measure(View.java:18834)
  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5953)
  at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
  at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2685)
  at android.view.View.measure(View.java:18834)
  at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2131)
  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1237)
  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1474)
  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1125)
  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6100)
  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
  at android.view.Choreographer.doCallbacks(Choreographer.java:670)
  at android.view.Choreographer.doFrame(Choreographer.java:606)
  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5525)
  at java.lang.re
  </code></pre>