Using CardView and RecyclerView in my layout files throws an exception

前端 未结 4 1415
[愿得一人]
[愿得一人] 2021-02-13 20:06

So I\'ve been taking a shot at the Material Design of Android Preview L. I imported both the CardView and the RecyclerView libraries.

I use the

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-13 20:50

    I am using Eclipse and faced the same issue. As suggested by user7610, you need to call recyclerView.setLayoutManager() to get over this.

    Here is how i solved it..

    Create a member variable..

    RecyclerView.LayoutManager mLayoutManager;
    

    In onCreate() or onCreateView()

    recyclerView = (RecyclerView) view
                    .findViewById(R.id.business_recycler_view);
    recyclerView.setHasFixedSize(true);
    
    mLayoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(mLayoutManager);
    

    This solved my NullPointerException.

提交回复
热议问题