title: NullPointerException after starting activity from onClickListener inside RecyclerView
body: <p>I'm getting the following error in logcat after calling <code>startActivity</code> from <code>onClickListener</code> inside a <code>RecyclerView</code> in a <code>Fragment</code>.</p>
  
  <pre><code>java.lang.NullPointerException
          at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:1764)
          at android.view.View.measure(View.java:15293)
          at android.widget.LinearLayout.measureVertical(LinearLayout.java:861)
          at android.widget.LinearLayout.onMeasure(LinearLayout.java:602)
          at android.view.View.measure(View.java:15293)
  </code></pre>
  
  <p>This happens after the other activity has been created (<code>OnCreate</code> called)</p>
  
  <p>Here's the <code>Fragment</code>'s <code>onViewCreated</code>:</p>
  
  <pre><code>public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      View view = getView();
      RecyclerView list = (RecyclerView) view.findViewById(R.id.list);
  
      list.setHasFixedSize(true);
      list.addItemDecoration(new DividerItemDecoration(getResources()));
  
      //Tried commenting out three of the following lines, no effect
      final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
      list.setLayoutManager(layoutManager);
      list.setItemAnimator(new DefaultItemAnimator());
  
      ArrayList&lt;TimelineItem&gt; timelineItems = new ArrayList&lt;&gt;();
      //populating the list with dummy data
  
      adapter = new TimelineAdapter(timelineItems);
      //this sets the onclick listener on the view inside the ViewHolder
      adapter.setPrimaryClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              openProfile();
          }
      });
  
      list.setAdapter(adapter);
  </code></pre>
  
  <p>Code for <code>openProfile</code>:</p>
  
  <pre><code>public void openProfile(){
      Intent intent = new Intent(getActivity(), ProfileActivity.class);
      //NPE happens after this
      getActivity().startActivity(intent);
  }
  </code></pre>
  
  <p>Adapter code:</p>
  
  <pre><code>@Override
  public void onBindViewHolder(TimelineAdapter.ViewHolder viewHolder, int i) {
      TimelineItem timelineItem = dataSet.get(i);
  
      //bunch of findViewById
  
      secondaryAction.setOnClickListener(secondaryClickListener);
      textContent.setOnClickListener(primaryClickListener);
      avatar.setOnClickListener(primaryClickListener);
  }
  </code></pre>
  
  <p>Turns out that this error always happens when switching to a new activity. Not specific to this <code>OnClickListener</code></p>