片段中 RecyclerView 的 NullPointerException

NullPointerException for RecyclerView In fragment

尝试使用片段内的回收视图实现卡片列表。每次我 运行 尝试打开片段时它都会崩溃。我正在学习本教程 https://developer.android.com/training/material/lists-cards.html#Dependencies and also this one http://code.tutsplus.com/tutorials/getting-started-with-recyclerview-and-cardview-on-android--cms-23465

Logcat 崩溃的地方。

    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setHasFixedSize(boolean)' on a null object reference

circles_tab.xml 片段

<android.support.v7.widget.RecyclerView
    android:id="@+id/circleList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:layout_marginTop="12dp"/>

CirclesFragment

public class CirclesFragment extends Fragment {

public ArrayList<String> circles = new ArrayList<String>();
public CharSequence[] circlesList;
public String[] circlesArray = new String[circles.size()];
private List<Person> persons;


private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;

ButtonFloat FAB;
Dialog dialog;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v =inflater.inflate(R.layout.circles_tab,container,false);

    // Create Cards list

    mRecyclerView = (RecyclerView)getActivity().findViewById(R.id.circleList);
    mRecyclerView.setHasFixedSize(false);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    initializeData();
    mAdapter  = new RVAdapter(persons);
    mRecyclerView.setAdapter(mAdapter);

    return v;
}

private void initializeData(){
    persons = new ArrayList<>();
    persons.add(new Person("Peter Parker", R.drawable.logo));
    persons.add(new Person("Miles Morales",R.drawable.logo));
    persons.add(new Person("Oliver Queen", R.drawable.logo));
}

这个主题有很多类似的问题,但大多数都没有得到解决。任何帮助将不胜感激。

谢谢大家

改变

 mRecyclerView = (RecyclerView)getActivity().findViewById(R.id.circleList);

 mRecyclerView = (RecyclerView)v.findViewById(R.id.circleList);