渲染问题:Android Studio 1.1.0 中 android.support.v7.widget.RecyclerView 的 java.lang.NullPointerException [英] Rendering Problems: java.lang.NullPointerException at android.support.v7.widget.RecyclerView in Android Studio 1.1.0

查看:30
本文介绍了渲染问题:Android Studio 1.1.0 中 android.support.v7.widget.RecyclerView 的 java.lang.NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将 android sdk 更新为 api 22 和 android studio 1.1.0.之后,我在 RecyclerView 上遇到了渲染问题.这是我得到的

 java.lang.NullPointerException在 android.support.v7.widget.RecyclerView.computeVerticalScrollRange(RecyclerView.java:1216)在 android.view.View.onDrawScrollBars(View.java:12943)在 android.view.View.draw(View.java:15237)在 android.support.v7.widget.RecyclerView.draw(RecyclerView.java:2440)在 android.view.View.draw(View.java:15140)在 android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)在 android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)在 android.view.ViewGroup.drawChild(ViewGroup.java:3405)在 android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)在 android.view.View.draw(View.java:15138)在 android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)在 android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)在 android.view.ViewGroup.drawChild(ViewGroup.java:3405)在 android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)在 android.view.View.draw(View.java:15234)在 android.view.View.draw(View.java:15140)在 android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)在 android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)在 android.view.ViewGroup.drawChild(ViewGroup.java:3405)在 android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1086)在 android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)在 android.view.View.draw(View.java:15138)在 android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)在 android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)在 android.view.ViewGroup.drawChild(ViewGroup.java:3405)在 android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)在 android.view.View.draw(View.java:15138)在 android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)在 android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)在 android.view.ViewGroup.drawChild(ViewGroup.java:3405)在 android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)在 android.view.View.draw(View.java:15234)在 android.view.View.draw(View.java:15140)在 android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)在 android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)在 android.view.ViewGroup.drawChild(ViewGroup.java:3405)在 android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)在 android.view.View.draw(View.java:15234)

<块引用>

我在 xml 预览/设计中遇到此异常,因此我无法查看xml设计.

项目运行正常,无一例外.这是我的小部件

 

这是我的代码

 recyclerView= (RecyclerView) findViewById(R.id.my_recycler_view);layoutManager=new GridLayoutManager(this,2);recyclerView.setLayoutManager(layoutManager);recyclerView.setHasFixedSize(true);recyclerView.setItemAnimator(new DefaultItemAnimator());

如何解决这个问题?

解决方案

当我从 RecyclerView 的 xml 文件中取出这一行时,我的问题解决了:

android:scrollbars="vertical"

我正在使用以下依赖项:

依赖项{编译文件树(目录:'libs',包括:['*.jar'])编译'com.android.support:appcompat-v7:22.0.0'编译'com.android.support:recyclerview-v7:22.0.0'编译'com.android.support:cardview-v7:22.0.0'}

此解决方案的评论员指出了此问题的根源-要解决此问题,您只需确保在设置了滚动条属性的 RecyclerView 之前设置了 RecyclerView 的 LayoutManager.

I have recently updated android sdk to api 22 and android studio 1.1.0. After that I am getting rendering issues on RecyclerView. Here is what I am getting

  java.lang.NullPointerException
at android.support.v7.widget.RecyclerView.computeVerticalScrollRange(RecyclerView.java:1216)
at android.view.View.onDrawScrollBars(View.java:12943)
at android.view.View.draw(View.java:15237)
at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:2440)
at android.view.View.draw(View.java:15140)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15138)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15234)
at android.view.View.draw(View.java:15140)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1086)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15138)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15138)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15234)
at android.view.View.draw(View.java:15140)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15234)

I am getting this exception on xml preview/design, so I am not able to view the xml design.

The project is working fine without any exception. Here is my widget

 <android.support.v7.widget.RecyclerView
            android:id="@+id/my_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="8"
            android:layout_gravity="center"
            android:gravity="center"
            android:scrollbars="vertical"
            android:fadeScrollbars="false"
            />

This is my code

    recyclerView= (RecyclerView) findViewById(R.id.my_recycler_view);
    layoutManager=new GridLayoutManager(this,2);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());

How to solve this issue?

解决方案

My problem was solved when I took out this line from the xml file for the RecyclerView:

android:scrollbars="vertical"

I am using the following dependencies:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.android.support:recyclerview-v7:22.0.0'
    compile 'com.android.support:cardview-v7:22.0.0'
}

EDIT: The root of this issue was pointed out by commentators on this solution - to solve the problem, you can just ensure that the LayoutManager for the RecyclerView is set before you display the RecyclerView with the scrollbars property set.

这篇关于渲染问题:Android Studio 1.1.0 中 android.support.v7.widget.RecyclerView 的 java.lang.NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆