简体   繁体   English

Android RecyclerView LayoutManager异常

[英]Android RecyclerView LayoutManager Exception

Hi I'm having an issue with the new Android Lollipop RecyclerView 嗨,我遇到了新的Android Lollipop RecyclerView

It keeps crashing with the following exception: 因以下异常而崩溃

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 可以在此处找到完整堆栈跟踪

The code used to initiate the RecyclerView is the same mostly the same as the tutorial, however for some reason this still complains. 用于启动RecyclerView的代码与教程大致相同,但由于某种原因,这仍然是抱怨。 Any help would be greatly appreciated. 任何帮助将不胜感激。

The code can be accessed at: gist here and layout: this gist 可以在以下位置访问代码: gist here和layout: this gist

None of the views , or objects are null viewsobjects都不为null

Add the following code: 添加以下代码:

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

Before adding adapter: 添加适配器之前

recyclerView.setAdapter(adapter);

In the android Api level 22 it will not give the error. 在Android Api级别22,它不会给出错误。 Instead it skips the layout if the Adapter is not found. 相反,如果找不到适配器,它会跳过布局。

By showing the warning: 通过显示警告:

RecyclerView﹕ No adapter attached; RecyclerView:没有连接适配器; skipping layout 跳过布局

But your app will not crash and runs, but recyclerView doesn't shown. 但是你的应用程序不会崩溃并运行,但recyclerView没有显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RecyclerView没有LayoutManager android.support.v7.widget.RecyclerView - RecyclerView has no LayoutManager android.support.v7.widget.RecyclerView '布尔android.support.v7.widget.RecyclerView $ LayoutManager.canScrollVertically()' - 'boolean android.support.v7.widget.RecyclerView$LayoutManager.canScrollVertically()' Android,包装RecyclerView LayoutManager,RTL,自下而上 - Android, Wrapping RecyclerView LayoutManager, RTL, Bottom-To-Top 如何在 Recyclerview/Layoutmanager 中获取 Scrollposition? - How to get the Scrollposition in the Recyclerview/Layoutmanager? 为片段创建RecyclerView时LayoutManager和RecyclerView问题 - LayoutManager and RecyclerView Issues When Creating RecyclerView For Fragment Android:RecyclerView 空指针异常 - Android: RecyclerView nullpointer exception android.view.InflateException:二进制XML文件第2行:RecyclerView没有LayoutManager - android.view.InflateException: Binary XML file line #2: RecyclerView has no LayoutManager 尝试调用虚方法 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager - Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager RecyclerView、RecyclerView.Adapter和RecyclerView.LayoutManager在哪里声明? - Where to declare RecyclerView, RecyclerView.Adapter and RecyclerView.LayoutManager? 这是什么“RecyclerView 没有 LayoutManager androidx.recyclerview.widget.RecyclerView”错误? - What is this "RecyclerView has no LayoutManager androidx.recyclerview.widget.RecyclerView" error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM