title: Null pointer exception while setting up recycler view in fragment
body: <p>I am getting this specific error during the runtime of my android app: </p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method`'void android.support.v7.widget.RecyclerView.setHasFixedSize(boolean)' on a null object reference
                                                                                 at com.monkeyengineer.project.MyFragment.onCreateView(MyFragment.java:36)
  </code></pre>
  
  <p>I have checked the android recycler view and adapter documentation but it is not helping me with why this is crashing.</p>
  
  <p>Here is my code in my Fragment where I am calling the <code>findViewById</code> method on the container view (import statements are omitted for brevity):</p>
  
  <pre><code>public class MyFragment extends Fragment {
  
      private List&lt;Project&gt; data;
      private RecyclerView recyclerView;
      private TextView textView;
  
      private boolean mIsRecyclerViewVisible = true;
  
      public MyFragment() {
          // Required empty public constructor
      }
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View mView = inflater.inflate(R.layout.my_fragment, container, false);
          textView = (TextView) container.findViewById(R.id.text_view);
          recyclerView = (RecyclerView) container.findViewById(R.id.recycler_view);
          recyclerView.setHasFixedSize(true);
  
          LinearLayoutManager mLayoutManager = new LinearLayoutManager(getContext());
          mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
          recyclerView.setLayoutManager(mLayoutManager);
  
          Adapter adapter = new ProjectsAdapter(data);
          recyclerView.setAdapter(adapter);
  
          if (data != null) {
              textView.setVisibility(View.INVISIBLE);
              mIsRecyclerViewVisible = true;
          } else {
              recyclerView.setVisibility(View.INVISIBLE);
              mIsRecyclerViewVisible = false;
          }
          return mView;
      }
  
      @Override
      public void onStart() {
          super.onStart();
          if (mIsRecyclerViewVisible) {
              recyclerView.setVisibility(View.VISIBLE);
              textView.setVisibility(View.INVISIBLE);
          } else {
              recyclerView.setVisibility(View.INVISIBLE);
              textView.setVisibility(View.VISIBLE);
          }
      }
  
      @Override
      public void onStop() {
          super.onStop();
          mIsRecyclerViewVisible = data != null;
      }
  }
  </code></pre>
  
  <p>Here is my fragment layout:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      tools:context="com.monkeyengineer.project.MyFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recycler_view"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:scrollbars="vertical" /&gt;
  
      &lt;TextView
          android:id="@+id/text_view"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:height="45dp"
          android:drawableLeft="@android:drawable/ic_input_add"
          android:drawableStart="@android:drawable/ic_input_add"
          android:drawablePadding="8dp"
          android:gravity="start|center"
          android:padding="8dp"
          android:text="Add stuff."
          android:textStyle="bold"
          android:layout_gravity="center_horizontal"
          android:layout_centerVertical="true"
          android:layout_centerHorizontal="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>So why is it giving a null pointer exception, it must be because the recycler view object is being assigned to a null value but I can not think why.</p>
  
  <p>Thanks.</p>