我得到的是异常 -
Caused by: java.lang.IllegalStateException: RecyclerView has no LayoutManager
at android.support.v7.widget.RecyclerView.generateLayoutParams(RecyclerView.java:2820)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:757)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.peoplecloud.app.guggu.NavigationDrawerFragment.onCreateView(NavigationDrawerFragment.java:75)
at android.app.Fragment.performCreateView(Fragment.java:1700)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:866)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1142)
at android.app.Activity.onCreateView(Activity.java:4803)
我添加了以下代码,但是我仍然遇到此异常 -
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mDrawerList.setLayoutManager(layoutManager);
如果删除回收站视图中的内容,则没有例外。
答案 0 :(得分:11)
从布局文件中的RecyclerView
中删除子元素。我不知道那些应该是什么,但他们不应该是RecyclerView
的孩子。
答案 1 :(得分:0)
mDrawerList.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
llm.setOrientation(LinearLayoutManager.VERTICAL);
mDrawerList.setLayoutManager(llm);
在setHasFixedSize()
语句之前LayoutManager
为我解决了问题。