I am trying to pass a context in the the fragment onCreateVIew() method but I am getting the following error.
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
Here's my code
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.zoggfrombetelgeuse.closet.MySQL.mDownloader;
public class HomeFragment extends Fragment {
public HomeFragment() {
    // Required empty public constructor
}
static String urlAddress = "http://localhost/my-site/dbGet.php";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_home, container, false);
    final RecyclerView rv = (RecyclerView) view.findViewById(R.id.card_view);
    rv.setLayoutManager(new LinearLayoutManager(getActivity()));
    final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_layout);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            new mDownloader(HomeFragment.this.getActivity(), urlAddress, rv, swipeRefreshLayout).execute();
        }
    });
    return view;
}
}
Someone please explain this error in simple language and help me fix it. I have read other questions, I used onAttach() but didn't work
HomeFragment.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.zoggfrombetelgeuse.closet.HomeFragment">
<!-- TODO: Update blank fragment layout -->
<android.support.v4.widget.SwipeRefreshLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/swipe_layout">
<android.support.v7.widget.RecyclerView
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:id="@+id/recycler_view"
    android:scrollbars="vertical">
    </android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
