NullPointerException异常在RecycleView [英] NullPointerException at RecycleView

查看:242
本文介绍了NullPointerException异常在RecycleView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图用双向LIB的卧式列表视图FPGA实现,所以我得到了RecycleView lib和双向的,但在两个运行时和XML我收到此异常:

i've been trying to use the TwoWay lib for a horizonal listview implemention, so i got the RecycleView lib and the TwoWay, but at both run time and the xml i receive this Exception :

09-21 01:46:52.148: E/AndroidRuntime(12471): FATAL EXCEPTION: main
09-21 01:46:52.148: E/AndroidRuntime(12471): java.lang.NullPointerException
09-21 01:46:52.148: E/AndroidRuntime(12471):    at 
com.lifemate.lmmessenger.recycleview.RecyclerView.onMeasure(RecyclerView.java:1346)
09-21 01:46:52.148: E/AndroidRuntime(12471):    at  
android.view.View.measure(View.java:12881)
09-21 01:46:52.148: E/AndroidRuntime(12471):    at   
android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:599)
09-21 01:46:52.148: E/AndroidRuntime(12471):    at 
android.widget.RelativeLayout.onMeasure(RelativeLayout.java:381)
09-21 01:46:52.148: E/AndroidRuntime(12471):    at 
android.view.View.measure(View.java:12881)

我搜索了很多,我发现了此解决方案:

i searched alot and i found out this solution :

          bgListView.setHasFixedSize(true);

          mLayoutManager = new LinearLayoutManager(this);
          bgListView.setLayoutManager(mLayoutManager);

但后来我意识到,除了一切发生在任何code编译之前创建视图!
没有任何一个有任何想法,这是为什么?

but then i realized that the exception happenes at creating the view before any code is compiled! does any one have any idea why is this?

推荐答案

我想以例外发生在创建视图你的意思是,你看到在编辑器中的例外。这是不是一个错误,而缺乏与IDE集成。回收者视图不无布局管理工作。由于code,设置布局管理器不会在IDE中执行,您看到此错误。

I assume by "the exception happens at creating the view" you mean you are seeing the exception in your editor. This is not a bug, rather a lack of integration with the IDE. A recycler view does not work without a layout manager. Since the code that sets the layout manager is not executed in the IDE, you see this error.

在将来,将有更好的集成。

In the future, there will be better integration.

这篇关于NullPointerException异常在RecycleView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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