java.lang.IllegalStateException: RecyclerView has no LayoutManager

匿名 (未验证) 提交于 2019-12-03 09:06:55

问题:

I am getting below exception-

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) 

I have added the following code,however i am still getting this exception-

 LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());     layoutManager.setOrientation(LinearLayoutManager.VERTICAL);     mDrawerList.setLayoutManager(layoutManager); 

If I remove the content inside recycler view then there is no exception.

回答1:

Remove the child elements from RecyclerView in your layout file. I don't know what those are supposed to be, but they are not supposed to be children of the RecyclerView.



回答2:

mDrawerList.setHasFixedSize(true); LinearLayoutManager llm = new LinearLayoutManager(getActivity()); llm.setOrientation(LinearLayoutManager.VERTICAL); mDrawerList.setLayoutManager(llm); 

Having setHasFixedSize() before the LayoutManager statement fixed the issue for me.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!