Android RecyclerView LayoutManager异常 [英] Android RecyclerView LayoutManager Exception
本文介绍了Android RecyclerView LayoutManager异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了新的Android Lollipop RecyclerView
它保持崩溃,但有以下例外:
Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView$LayoutManager.onMeasure(android.support.v7.widget.RecyclerView$Recycler, android.support.v7.widget.RecyclerView$State, int, int)' on a null object reference
完整的堆栈跟踪可以在这里找到
Full stack trace can found here
用于启动RecyclerView
的代码与本教程几乎相同,但是由于某些原因,仍然会抱怨.任何帮助将不胜感激.
The code used to initiate the RecyclerView
is the same mostly the same as the tutorial, however for some reason this still complains. Any help would be greatly appreciated.
可以在以下位置访问该代码:要点此处和布局:
The code can be accessed at: gist here and layout: this gist
views
或objects
都不是null
推荐答案
添加以下代码:
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
之前添加适配器:
recyclerView.setAdapter(adapter);
这篇关于Android RecyclerView LayoutManager异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文